现在我的 Angular Controller 中有一个相对简单的模板,
<div class="dropdown-menu" [attr.aria-labelledby]="item.name" *ngIf="item.children">
<button class="dropdown-item" *ngFor="let child of item.children; let last = last" (click)="child.action">{{child.name}} <hr *ngIf="!last"></button>
</div>
但是,当所有内容都编译完毕后,我的(单击)事件绑定(bind)就会从 DOM 中消失。如果我将按钮更改为链接元素并将 (click)
更改为 [href]
,它就会起作用。
感谢任何帮助,只是开始掌握 Angular2 :)
编辑: 抱歉,我有一瞬间的疯狂(愚蠢)......
最佳答案
你的意思可能是
(click)="child.action()"
或
(click)="child.action($event)"
否则不会被调用。
关于javascript - 使用 *ngFor 时, Angular 事件绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42697219/