-1
尝试在ngFor期间通过点击输出函数调用。我不知道如何引用它。Angular2 onclick in ngfor
我是新来的angualr2,我不确定这是否是实现此目的的正确方法。我希望有任何建议。
export class Navbar {
constructor() {}
public userNavs = [
{ title: 'Account', click: 'account()' },
{ title: 'Logout', click: 'logout()' }
]
logout() {
console.log('working');
}
account(){
console.log('working');
}
ngOnInit() {}
}
////HTML////
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="userdropdown">
<li *ngFor="let nav of userNavs" ><a class="dropdown-item btn-sm" (click)="{{ nav.click }}" >{{ nav.title }}</a></li>
</ul>
这是从你的描述,你正在努力实现的代码真的不清楚,它看起来像一个烂摊子。 –
不要在输出属性内使用插值'(点击)' – yurzui