import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-reactive-favorite-color',
template: `
Favorite Color: <input type="text" [formControl]="favoriteColorControl">
`
})
export class ReactFormComponent {
favoriteColorControl = new FormControl('');
}
網上很多文章,隻介紹了要使用圖中的formControl指令,需要導入ReactiveFormsModule,但卻并未解釋原因。
按住滑鼠左鍵,單擊[formControl], 自動來到forms.d.ts檔案,根據關鍵字formControl搜尋(注意,打開大小寫敏感的搜尋開關),即可找到[formControl]定義的位置:第1963行的DirectiveDefWithMeta函數内。
