issue:用[(ngModel)]="property"指令雙向數據綁定,報錯。
reason1:使用ngModel綁定數據需要注入FormsModule模塊,在app.module.ts中全局注入
@NgModule({
imports: [
FormsModule
]
})
reason2:不符合ng綁定數據的書寫規則
規則一:在input標簽中添加name屬性【推薦使用】
<input [(ngModel)]='params.username' name="username" type="text">
規則二:在input標簽中添加代碼[ngModelOptions]="{standalone: true}"
<input [(ngModel)]='params.username' [ngModelOptions]="{standalone: true}" type="text">