我正在使用 ngFor 迭代 Angular 4.x 中特定类型 [Menu] 的集合。
然后循环菜单对象的集合属性(菜单项).
不幸的是,该属性在我的 IDE 中未知(Eclipse https://en.wikipedia.org/wiki/Eclipse_%28software%29+ Angular IDE),即使 Menu 类将 items 属性定义为 MenuItem 数组。
有解决办法吗?
相关类声明 -
export class MenuBase {
id: string;
title: string;
isPublic: boolean;
roles: string[];
items: MenuItem[];
position: number;
// rest of class omitted
}
export class MenuItem extends MenuBase {
menuItemType: MenuItemType;
callback: () => void;
location: string;
constructor (options: any) {
super(options);
this.location = options.location;
this.menuItemType = options.menuItemType || MenuItemType.location;
this.callback = options.callback;
}
}
export class Menu extends MenuBase {
constructor (options: any) {
super(options);
}
}
附加信息
这是我正在从事的项目:https://github.com/savantly-net/ngx-menu https://github.com/savantly-net/ngx-menu。
该项目将在 Eclipse 中显示错误,即使它是有效的。
我从未创建过任何文档,但我在这里使用了它 -https://github.com/savantly-net/sprout-platform/tree/master/web/sprout-web-ui https://github.com/savantly-net/sprout-platform/tree/master/web/sprout-web-ui
我所取得的成功是为模板创建了一个新组件*ngFor
将渲染并输入该内容。
容器模板:
<ng-container *ngFor="item of items" >
<my-custom-component [item]="item"></my-custom-component>
</ng-container>
自定义组件模板:
<div *ngIf="item.menuItemType == 'dropdown'">
<!-- -->
</div>
ts file:
@Component({})
export class MyCustomComponent {
@Input() item: MenuItem
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)