我有一个直接从this ng-bootstrap example复制的按钮下拉菜单。
该下拉列表有效,但如果按如下所示向下拉按钮添加点击处理程序,则在单击该按钮时不会触发:
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Toggle dropdown</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<button ngbDropdownItem click="clicked()">Not Me</button>
<button ngbDropdownItem click="clicked()">Me neither</button>
<button ngbDropdownItem click="clicked()">Nor me</button>
</div>
</div>
这是原始示例中的Stackblitz example分叉。
我做的事真的很愚蠢吗?预先感谢。
答案 0 :(得分:1)
click
应该用方括号括起来:
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Toggle dropdown</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<button ngbDropdownItem (click)="clicked()">Not Me</button>
<button ngbDropdownItem (click)="clicked()">Me neither</button>
<button ngbDropdownItem (click)="clicked()">Nor me</button>
</div>
</div>
还要确保已在组件中实现了方法clicked()