{"id":1966,"date":"2022-02-07T00:00:10","date_gmt":"2022-02-06T15:00:10","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1966"},"modified":"2022-02-06T23:14:36","modified_gmt":"2022-02-06T14:14:36","slug":"angular-stackblitz-com-angular-introduction-reactive-form","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2022\/02\/07\/angular-stackblitz-com-angular-introduction-reactive-form\/","title":{"rendered":"Angular\u59cb\u3081\u307e\u3057\u305f &#8211; \u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u305d\u3057\u3066\u3001stackblitz.com\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u307f\u8fbc\u3093\u3067\u307f\u308b"},"content":{"rendered":"\n<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002<br>\u5148\u65e5\u306b\u5f15\u304d\u7d9a\u304d\u3001Angular\u3092\u52c9\u5f37\u3057\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u3063\u3066\u3001\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u51fa\u6765\u4e0a\u304c\u308a\u30a4\u30e1\u30fc\u30b8\">\u51fa\u6765\u4e0a\u304c\u308a\u30a4\u30e1\u30fc\u30b8<\/h2>\n\n\n\n<p>\u3000\u3000\u4eca\u56de\u306f\u3001\u305f\u307e\u305f\u307e\u30cb\u30e5\u30fc\u30c8\u30f3\uff0d\u30e9\u30d5\u30bd\u30f3\u6cd5\u306b\u3064\u3044\u3066\u8cea\u554f\u304c\u3042\u3063\u305f\u306e\u3067\u3001Angular\u3067\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002\u30eb\u30fc\u30c8\u3092\u6c42\u3081\u305f\u3044\u5024\u300ck\u300d\u3092\u5165\u529b\u3057\u3066\u3001Calc\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u6f38\u5316\u5f0f\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002\u4e8c\u4e57\u3057\u305f\u7d50\u679c\u304c\u300ck\u300d\u3068\u306e\u8aa4\u5dee0.01\u672a\u6e80\u306b\u306a\u3063\u305f\u3089\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"881\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image.png\" alt=\"\" class=\"wp-image-1973\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image.png 631w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image-215x300.png 215w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><figcaption>\u30cb\u30e5\u30fc\u30c8\u30f3\uff0d\u30e9\u30d5\u30bd\u30f3\u6cd5\u306e\u5b9f\u884c\u7d50\u679c<\/figcaption><\/figure>\n\n\n\n<p>\u3000\u4eca\u56de\u3082\u3001statsblitz.com\u3092\u5229\u7528\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u4f5c\u696d\u4e2d\u306b\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u300chello.component.ts\u300d\u3092\u524a\u9664\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u3067\u307e\u3057\u305f\u3002\u3057\u3070\u3089\u304f\u89e3\u6c7a\u3067\u304d\u306a\u304f\u3066\u3001\u4f55\u304b\u306e\u8a2d\u5b9a\u304c\u3042\u308b\u306e\u304b\u3068\u3001\u30a6\u30ed\u30a6\u30ed\u3057\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u56de\u907f\u7b56\u3092\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Error in src\/app\/hello.component.ts (1:1)\nFile '\/~\/src\/app\/hello.component.ngtypecheck.ts' not found.<\/pre>\n\n\n\n<p>\u3000\u4f55\u306e\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3001\u304a\u304b\u3057\u306a\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u308b\u3060\u3051\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u3088\u3046\u3067\u3057\u305f\u3002\u753b\u9762\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u306e\u5de6\u4e0b\u306e\u300cDEPENDENCIES\u300d\u3092\u30dd\u30a4\u30f3\u30c8\u3059\u308b\u3068\u3001\u304f\u308b\u308a\u3068\u306a\u3063\u305f\u77e2\u5370\u304c\u767b\u5834\u3059\u308b\u306e\u3067\u3001\u305d\u3061\u3089\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3068\u3053\u308d\u3001\u3057\u3070\u3089\u304f\u5f85\u3063\u3066\u3001\u30a8\u30e9\u30fc\u304c\u6d88\u3048\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"152\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image-1.png\" alt=\"\" class=\"wp-image-1974\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image-1.png 567w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2022\/02\/image-1-300x80.png 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><figcaption>DEPENDENCIES\u306e\u89e3\u6c7a<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u300cFormGroup\u300d\u3067\u3059\u306d\u3002TypeScript\u5074\u3067\u300cmyGroup\u300d\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001\u4eca\u56de\u306fFormBuilder\u3092\u4f7f\u3063\u3066\u300ck\u300d\u3092\u5b9a\u7fa9\u3057\u307e\u3057\u305f\u3002\u307e\u305f\u3001Validators\u3092\u4f7f\u3063\u3066\u3001\u6b63\u306e\u6570\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<br>onSubmit()\u547c\u3073\u51fa\u3057\u6642\u3001\u6f38\u5316\u5f0f\u3067\u8a08\u7b97\u3092\u5b9f\u884c\u3057\u3066\u3001\u4e8c\u4e57\u3057\u305f\u7d50\u679c\u304ck\u306b\u8fd1\u3065\u3044\u3066\u5dee\u304c0.01\u3092\u4e0b\u56de\u3063\u305f\u3068\u3053\u308d\u3067\u51e6\u7406\u3092\u5b8c\u4e86\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"typescript\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import { Component, OnInit } from '@angular\/core';\nimport { FormGroup, FormBuilder, Validators } from '@angular\/forms';\n\n@Component({\n  selector: 'app-x2',\n  templateUrl: '.\/x2.component.html',\n  styleUrls: ['.\/x2.component.css'],\n})\nexport class X2Component implements OnInit {\n  myGroup: FormGroup;\n  results: string[];\n  guess: number;\n\n  constructor(private fb: FormBuilder) {}\n\n  ngOnInit() {\n    this.myGroup = this.fb.group({\n      k: [24, Validators.min(0)],\n    });\n  }\n\n  get k() { return this.myGroup.get('k'); }\n\n  onSubmit() {\n    console.log('Executed!')\n    this.results = [];\n    let k: number = this.k.value;\n    let epsilon: number = 0.01;\n    let guess: number = k \/ 2;\n    let newGuess: number;\n    while (Math.abs(guess * guess - k) >= epsilon) {\n      newGuess = guess - (guess ** 2 - k) \/ (2 * guess);\n      if (this.results.length == 0) {\n        this.results.push(guess.toString() + ' => ' + newGuess.toString());\n      } else {\n        this.results.push(' => ' + newGuess.toString());\n      }\n      guess = newGuess;\n    }\n    this.guess = guess;\n  }\n}\n<\/pre>\n\n\n\n<p>\u3000\u305d\u3057\u3066\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eHTML\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;p>\n\u30cb\u30e5\u30fc\u30c8\u30f3\uff0d\u30e9\u30d5\u30bd\u30f3\u6cd5\u3067k\u306e\u6839\u3092\u6c42\u3081\u307e\u3059\u3002\n&lt;\/p>\n&lt;p>\nf(x) = x&lt;sup>2&lt;\/sup> - k&lt;br>\nx&lt;sub>n + 1&lt;\/sub> = x&lt;sub>n&lt;\/sub> - f(x) \/ f'(x) = x&lt;sub>n&lt;\/sub> - (x&lt;sub>n&lt;\/sub>&lt;sup>2&lt;\/sup> - k)\/2x&lt;sub>n&lt;\/sub>\n&lt;\/p>\n&lt;form [formGroup]=\"myGroup\" (submit)=\"onSubmit()\">\n  &lt;table>\n    &lt;tr>\n      &lt;th>k&lt;\/th>\n      &lt;td>&lt;input type=\"number\" formControlName=\"k\">&lt;\/td>\n    &lt;\/tr>\n    &lt;tr>\n      &lt;th>&lt;\/th>\n       &lt;td *ngIf=\"k.invalid\" [style.color]=\"'red'\">\u6b63\u306e\u6570\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&lt;\/td>\n    &lt;\/tr>\n    &lt;tr>\n      &lt;th>&lt;\/th>\n      &lt;td>\n        &lt;input type=\"submit\" value=\"Calc\" [disabled]=\"myGroup.invalid\">\n      &lt;\/td>\n    &lt;\/tr>\n  &lt;\/table>\n&lt;\/form>\n&lt;ul>\n  &lt;li>\u307e\u305a\u3001guess = k \/ 2 = {{k.value}} \/ 2 = {{k.value \/ 2}} \u3068\u3057\u307e\u3059\u3002&lt;br>guess - (guess&lt;sup>2&lt;\/sup> - {{k.value}})\/ (2 \u00d7 guess)\u304c\u3088\u308a\u8fd1\u3044\u5024\u306b\u306a\u308b\u306e\u3067\u3001\u8a08\u7b97\u7d50\u679c\u306e\u8aa4\u5dee\u304c0.01\u306b\u306a\u308b\u307e\u3067\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002&lt;br>\n    &lt;p *ngIf=\"!results\">Calc\u3092\u62bc\u3057\u3066\u7d9a\u884c\u3057\u307e\u3059\u3002&lt;\/p>&lt;\/li>\n  &lt;li *ngFor=\"let ans of results\">{{ans}}&lt;\/li>\n&lt;\/ul>\n&lt;p *ngIf=\"guess\">{{guess}} * {{guess}} = {{guess * guess}}&lt;\/p>\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"wordpress\u3078\u306e\u7d44\u307f\u8fbc\u307f\">WordPress\u3078\u306e\u7d44\u307f\u8fbc\u307f<\/h2>\n\n\n\n<p>\u3000stackblitz.com\u3092\u898b\u3066\u3044\u308b\u3068\u3001\u300cShare\u300d\u30e1\u30cb\u30e5\u30fc\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u30af\u30ea\u30c3\u30af\u3057\u3066\u898b\u308b\u3068\u3001\u300cEmbed\u300d\u30bf\u30d6\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u306e\u3067\u3001WordPress\u306b\u7d44\u307f\u8fbc\u3081\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3001\u3068\u3001\u8abf\u3079\u3066\u7d44\u307f\u8fbc\u3093\u3067\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u7d44\u307f\u8fbc\u307f\u30d6\u30ed\u30c3\u30af\u306f\u3042\u308b\u306e\u3067\u3059\u304c\u3001stackblitz.com\u7528\u306e\u3082\u306e\u304c\u306a\u304f\u3001\u8abf\u3079\u3066\u3044\u308b\u3068<a href=\"https:\/\/github.com\/stackblitz\/core\/issues\/117\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u3053\u3053\">\u3053\u3053<\/a>\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3002iframe\u30bf\u30b0\u3092\u4f7f\u3063\u3066\u3001\u3068\u3044\u3046\u3053\u3068\u3060\u3063\u305f\u306e\u3067\u3001\u5b9f\u9a13\u3057\u3066\u307f\u307e\u3057\u305f\u3068\u3053\u308d\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3001\u5b9f\u884c\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<iframe loading=\"lazy\" id=\"inlineFrameExample\" title=\"Inline Frame Example\" width=\"500\" height=\"600\" src=\"https:\/\/stackblitz.com\/edit\/angular-ivy-xrfrw6?embed=1&amp;file=src\/app\/x2\/x2.component.html&amp;hideExplorer=1&amp;hideNavigation=1&amp;view=preview\">\n<\/iframe>\n\n\n\n<p>\u3000\u305f\u3060\u3001\u7de8\u96c6\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u753b\u9762\u3067\u306f\u300cCalc\u300d\u30dc\u30bf\u30f3\u306f\u52d5\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002iframe\u3067\u306fsubmit\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u305f\u3060\u3001\u78ba\u8a8d\u753b\u9762\u3067\u306f\u52d5\u4f5c\u3057\u307e\u3057\u305f\u3002\u3053\u3061\u3089\u306e\u539f\u56e0\u306f\u307e\u305f\u6a5f\u4f1a\u304c\u3042\u3063\u305f\u3089\u8abf\u3079\u3066\u307f\u307e\u3059\u3002\u516c\u958b\u3055\u308c\u305f\u5f8c\u306b\u5b9f\u884c\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u308f\u304b\u308a\u307e\u305b\u3093\u306e\u3067\u3001stackblitz.com\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f<a href=\"https:\/\/stackblitz.com\/edit\/angular-ivy-xrfrw6?file=src\/app\/x2\/x2.component.html\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u3053\u3061\u3089\">\u3053\u3061\u3089<\/a>\u3001\u5b9f\u884c\u7d50\u679c\u306f<a href=\"https:\/\/angular-ivy-xrfrw6.stackblitz.io\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u3053\u3061\u3089\">\u3053\u3061\u3089<\/a>\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u307e\u3068\u3081\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3000Angular\u306e\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u3063\u3066\u3001\u30da\u30fc\u30b8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002\u5148\u65e5\u306b\u5f15\u304d\u7d9a\u304d\u3001Angular\u3092\u52c9\u5f37\u3057\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u3063\u3066\u3001\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002 \u51fa\u6765\u4e0a\u304c\u308a\u30a4\u30e1\u30fc\u30b8 \u3000\u3000\u4eca\u56de\u306f\u3001\u305f\u307e &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2022\/02\/07\/angular-stackblitz-com-angular-introduction-reactive-form\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Angular\u59cb\u3081\u307e\u3057\u305f &#8211; \u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u305d\u3057\u3066\u3001stackblitz.com\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u307f\u8fbc\u3093\u3067\u307f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,8,2],"tags":[],"class_list":["post-1966","post","type-post","status-publish","format-standard","hentry","category-angular","category-program","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/comments?post=1966"}],"version-history":[{"count":13,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1966\/revisions"}],"predecessor-version":[{"id":1985,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1966\/revisions\/1985"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}