[英]Angular ERROR TypeError: Cannot set property 'name' of undefined
我試圖從我的表單中獲取一個值,但我不斷收到此錯誤。 這是代碼。 我的 formControlName 是值的“名稱”,我試圖將其放入地址類型的變量中,即我創建的 class。 變量為newAddress,表單組為addressForm。 這是我正在嘗試實現它的 function,這是我的地址 class。
onSubmit() {
this.newAddress.name = this.addressForm.value['name'];
console.log(this.newAddress.name);
this.addressForm.reset({
name: '',
addressLine1: '',
city: '',
state: '',
zipcode: '',
});
this.addressFormDirective.resetForm();
}
export class Address {
name: string;
addressLine1: string;
city: string;
state: string;
zipcode: string;
}
首先在構造函數中初始化它
this.newAddress=new Address()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.