簡體   English   中英

我們可以使用帶有 object 屬性的 [(ngModel)] 指令嗎?

[英]Can we use a [(ngModel)] directive with an object property?

我正在嘗試使用 object,如下所示:

 private userInfo: IUser; export interface IUser { userId: string; email: string; photoUrl?: string; displayName: string; location?: string; bio?: string; intDestination?: string[]; dateOfBirth?: any; education?: string; gender?: string; userSetting?: {turnOnNotify: boolean}; }
 <ion-card color="light"> <p>{{userInfo?.displayName}}</p> <input size="70" ngx-google-places-autocomplete [options]='options' [(ngModel)]="userInfo.location" #placesRef="ngx-places" (onAddressChange)="handleCityChange($event)" /> </ion-card>

但是 ngModel 不喜歡。 標識 object 屬性的符號

 core.js:6241 ERROR TypeError: Cannot read property 'location' of undefined at ProfilePage_Template (template.html:28)

有沒有辦法在 ngModel 中使用對象的屬性?

這是因為userInfo是私有的,如果你想訪問 Html 上的 userInfo,它需要是公共的。

 userInfo: IUser;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM