Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 从函数访问嵌套模型_Angular_Typescript - Fatal编程技术网

Angular 从函数访问嵌套模型

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

我正试图基于这个示例在我的ng select中构建searchFn

组件技术 Model.ts 正如您在我的组件中看到的,我正在尝试访问item.department.name,但它不起作用


“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;
}