Angular 一个简单的指令实现 阻止事件扩散

//指令定义

@Directive({ selector: `click
-stop-propagation` events: 'stopClick($event)' }) class ClickStopPropagation { stopClick(event:Event) { event.preventDefault(); event. stopPropagation(); } }
//使用
<button (click)="doSomething()" click-stop-propagation>

 

 

参考:

https://github.com/angular/angular/issues/2042

posted @ 2019-08-02 11:34  wolbo  阅读(409)  评论(0编辑  收藏  举报