有没有办法在ngFor中声明特定类型

Jer*_*emy 8 typescript angular

我正在使用ngFor迭代Angular 4.x中特定类型[菜单]的集合

然后循环显示菜单对象的集合属性[menu.items]

不幸的是,即使Menu类将items属性定义为MenuItem数组,该属性在我的IDE [Eclipse + Angular IDE]中还是未知的。

有什么想法吗?

红色花体

相关的类别声明-

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);
  }
}
Run Code Online (Sandbox Code Playgroud)

附加信息-这是我正在从事 的项目:https : //github.com/savantly-net/ngx-menu
即使有效,该项目也会在Eclipse中显示错误。

我从未创建任何文档,但在这里使用了它-https:
//github.com/savantly-net/sprout-platform/tree/master/web/sprout-web-ui

c_o*_*goo 5

我已经成功完成的工作是为*ngFor将要呈现并键入的模板创建一个新组件。

容器模板:

<ng-container *ngFor="item of items" >
  <my-custom-component [item]="item"></my-custom-component>
</ng-container>
Run Code Online (Sandbox Code Playgroud)

自定义组件模板:

<div *ngIf="item.menuItemType == 'dropdown'">
  <!-- -->
</div>

Run Code Online (Sandbox Code Playgroud)

ts文件:

@Component({})
export class MyCustomComponent {
  @Input() item: MenuItem
}
Run Code Online (Sandbox Code Playgroud)