錯誤 TS2339:型別上不存在屬性“值”
使用以下代碼時出現上述錯誤
HTML 中的代碼
<input type="text" (input)="title = $event.target.value" />
任何人都可以請指導我并為我提供解決方案嗎?
uj5u.com熱心網友回復:
我想你可以簡單地寫成這樣,
在您的組件中創建一個如下所示的事件處理函式,
onInput(e: any) {
this.title = e.target.value;
}
你的 HTML 檔案看起來像這樣,
<input type="text" (input)="onInput($event)" />
uj5u.com熱心網友回復:
正如@LukaszGawrys 在評論中已經提到的那樣,您可以使用 Angular 兩種方式的資料系結[(ngModel)]語法:
<input type="text" [(ngModel)]="title" name="title" />
為了ngModel作業,您需要匯入FormsModule為:
@NgModule({
declarations: [ ... ],
imports: [
...
FormsModule
]
})
export class AppModule { }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/400349.html
