Angular 从函数访问嵌套模型
我正试图基于这个示例在我的ng select中构建searchFn 组件技术 Model.ts 正如您在我的组件中看到的,我正在尝试访问item.department.name,但它不起作用Angular 从函数访问嵌套模型,angular,typescript,Angular,Typescript,我正试图基于这个示例在我的ng select中构建searchFn 组件技术 Model.ts 正如您在我的组件中看到的,我正在尝试访问item.department.name,但它不起作用 “Department[]”类型上不存在其显示属性“name”。与OP讨论后,发现模型不正确。这是正确的型号: export interface Person { id: string; name: string; description: string; departmen
“Department[]”类型上不存在其显示属性“name”。与OP讨论后,发现模型不正确。这是正确的型号:
export interface Person {
id: string;
name: string;
description: string;
department: Department;
}
你的stackblitz无效消息说明了一切。应该命名为departments的department是department对象的数组。数组没有任何名称属性。@EliyaCohen:您现在可以按JBNizet描述的那样尝试吗。。。。你把它修好,然后让它工作;我要找一个部门,有些不是功能。一旦我开始工作,将更改为部门Yeah department是arraygetting错误运算符“>”不能应用于类型“department[]”和“number”。让我们来看看。
export interface Person {
id: string;
name: string;
description: string;
department: Array<Department>;
}
export interface Department {
id: string;
name: string;
description: string;
}
export interface Person {
id: string;
name: string;
description: string;
department: Department;
}