我正在開發一個用戶可以注冊的應用程式,為此用戶必須撰寫諸如姓名、昵稱、密碼、身份型別等資料......
用戶模型:
export class User{
id: string;
name: string;
nickname: string;
password: string;
docType: {
documentTypeId: number;
}
}
組件.ts:
public insertUser(event: Event): void{
event.preventDefault();
const u: User = new User();
u.id = this.form.value.id;
u.name = this.form.value.name;
u.nickname = this.form.value.nickname;
u.password = this.form.value.password;
u.docType.documentTypeId = Number(this.form.value.typeId); // the error occurs here
/*send to API, save to DB... */
}
所以,當賦值為的值時會發生錯誤u.docType.documentTypeId,我不知道我做錯了什么。
uj5u.com熱心網友回復:
這是否有效:
u.docType = {
documentTypeId: Number(this.form.value.typeId);
}
我相信應該!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/354131.html
