我正在尝试将“禁用选项”应用于我的自定义按钮,但是当我将按钮设置为禁用时,单击事件仍然有效。如果启用了按钮,我只需要单击事件,如果禁用它则不需要。
代码:
<myngbutton [disabled]="disabled3" (click)="alertMsg()">Save 3</myngbutton>
问题是,click
您订阅的click
事件不是按钮元素上的事件,而是myngbutton
元素上的点击。您需要在您的myngbutton
组件上添加一个在button
元素点击时发出的事件发射器:
myngbutton.component.ts:
@Component({...})
export class MyngbuttonComponent {
[...]
@Output() onClick = new EventEmitter();
[...]
}
myngbutton.component.html:
<button [...] (click)="onClick.emit()">[...]</button>
app.component.html:
<myngbutton [disabled]="disabled1" (onClick)="alertMsg()">Save 1</myngbutton>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句