other responsesに示されているように、Angular2アプリケーションの初期ルーチンは、ngOnInit()メソッドで起動し、依存関係注入専用のコンストラクタを残す必要があります。ngOnInitではなく、コンストラクタでAngular2反応形式を作成するのはなぜですか?
しかし、私は以下のよReactive Forms tutorialで、フォームの初期化はコンストラクタである:
export class HeroDetailComponent3 {
heroForm: FormGroup; // <--- heroForm is of type FormGroup
constructor(private fb: FormBuilder) { // <--- inject FormBuilder
this.createForm();
}
createForm() {
this.heroForm = this.fb.group({
name: '', // <--- the FormControl called "name"
});
}
}
は本当に大きな違いがあるか、それだけでマイナーな問題ですか?
オープン。 –