0

我正在将应用程序迁移到 Dart 2 和 Angular 5。我在 html 文件中有这段代码

<material-list-item *ngFor="let key of keyList" 
    (trigger)="clickItem(key)">{{key}}
</material-list-item>

如果我在相应的 dart 文件中声明使用“materialDirectives”,一切正常,但如果我只导入“MaterialListItemComponent”,则不会触发对该项目的点击。

我实际上尝试添加更多指令,但使用以下列表不起作用:

MaterialButtonComponent,
MaterialIconComponent,
MaterialDialogComponent,
MaterialListComponent, 
MaterialListItemComponent,
MaterialInputComponent,
MaterialPopupComponent,
ModalComponent,
PopupSourceDirective,
ButtonDirective.

materialDirectives 已弃用,如果没有必要,我不想包含所有内容。寻找这个问题的答案,同时寻找一种方法来识别不同组件使用哪些指令。

4

1 回答 1

2

MaterialListItemComponent 扩展了具有触发逻辑的 ButtonDirective。所以这应该是你所需要的。与 NgFor 一起仅用于您示例中的代码。

与您的代码类似的演示使用:

FocusItemDirective,
FocusListDirective,
MaterialIconComponent,
MaterialListComponent,
MaterialListItemComponent,
MaterialSelectItemComponent,
NgFor

是否有任何运行时错误?

于 2018-08-15T02:11:50.960 回答