angular 中的参考接口字段
Reference interface field in angular
在打字稿中,我有一个带有供应商的命令界面:
export interface Command {
supplier?: Supplier;
}
export interface Supplier {
id?: number;
name: String;
}
我试图在我 select 供应商之前在 angular 输入文本中显示供应商的名称,但出现错误
error command.supplier is undefined
<input id="input" type="text" size="30" pInputText [(ngModel)]="command.supplier.name">
您需要在您的组件中对其进行初始化,例如:-
public component = {
supplier: {
id: null,
name: null
}
};
或在带有安全遍历运算符的模板中使用:-
<input id="input" type="text" size="30" pInputText [(ngModel)]="command.supplier.name">
在打字稿中,我有一个带有供应商的命令界面:
export interface Command {
supplier?: Supplier;
}
export interface Supplier {
id?: number;
name: String;
}
我试图在我 select 供应商之前在 angular 输入文本中显示供应商的名称,但出现错误
error command.supplier is undefined
<input id="input" type="text" size="30" pInputText [(ngModel)]="command.supplier.name">
您需要在您的组件中对其进行初始化,例如:-
public component = {
supplier: {
id: null,
name: null
}
};
或在带有安全遍历运算符的模板中使用:-
<input id="input" type="text" size="30" pInputText [(ngModel)]="command.supplier.name">