【发布时间】:2018-02-23 18:53:30
【问题描述】:
我正在使用 ngFor 在 Angular 4.x 中迭代特定类型 [Menu] 的集合
然后在菜单对象 [menu.items] 的集合属性上循环
不幸的是,在我的 IDE [Eclipse + 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
该项目将在 Eclipse 中显示一个错误,即使它是有效的。
我从未创建过任何文档,但我在这里使用了它 -
https://github.com/savantly-net/sprout-platform/tree/master/web/sprout-web-ui
【问题讨论】:
-
如果能像 *ngFor="let item: MenuItem of menu.items" 这样声明类型就好了
-
不,那不可能。
-
这是 AngularIDE 的一个已知问题。如果正确完成,代码应该仍然可以工作:genuitec.com/forums/topic/…
-
这个问题还没有解决办法吗?刚开始学习Angular 6/7,好像没解决。
-
如果您使用的是 VS Code 或 WebStorm,那么此链接可能会对您有所帮助:angular.io/guide/language-service。本质上,在 VS Code 中,您安装扩展“Angular 语言服务”,然后在
html文件中获得自动完成功能。在 WebStorm 中,您必须将其安装为开发依赖项@angular/language-service。您仍然无法添加类型,但您将获得自动完成功能(这就是我假设您需要一种类型的原因):)
标签: angular typescript