前提
Object is possibly 'null' が表示されないようにしたい
発生している問題・エラーメッセージ
TypeScript初心者です。 Object is possibly 'null' ソースコードの25、26行目で上記のエラーメッセージが表示されます。 参考書の通りに記述しています。 TypeScriptに改編があったのでしょうか? インターネットで調べたら、メソッドの書き方ばかりで、フィールドについては記述はありませんでした。 どうか方法を教えて欲しいです。
該当のソースコード
import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @Component({ selector: 'app-better-form', templateUrl: './better-form.component.html', styleUrls: ['./better-form.component.css'] }) export class BetterFormComponent implements OnInit { calcForm: FormGroup; result: string = "足し算しましょう"; constructor() { } ngOnInit() { this.calcForm = new FormGroup({ "fieldOne": new FormControl('0',Validators.required), "fieldTwo": new FormControl('0',[Validators.required, Validators.maxLength(5)]) }); } get fieldOne(){return this.calcForm.get("fieldOne");} get fieldTwo(){return this.calcForm.get("fieldTwo");} addAnyway() { let text1:string = this.fieldOne.value; let text2:string = this.fieldTwo.value; let resultStr: string = ""; if(Number.isNaN(Number(text1)) || Number.isNaN(Number(text2))) { resultStr = text1 + text2; }else { resultStr = `${text1}+${text2} = ${Number(text1) + Number(text2)}`; } this.result = resultStr; } clearResult() { this.result=""; } }
補足情報(FW/ツールのバージョンなど)
参考書籍
https://www.amazon.co.jp/gp/product/B07BXY3V2L/ref=ppx_yo_dt_b_d_asin_title_o01?ie=UTF8&psc=1

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。