1 变量控制
2
import {Component, AfterViewInit, Renderer, ViewChild, ElementRef} from '@angular/core';@Component({ template: `<button #button>...</button>`})
export class SampleComponent implements AfterViewInit { @ViewChild('button') button: ElementRef; private cancelClick: Function;
constructor(private renderer: Renderer) {}
ngAfterViewInit() { this.cancelClick = this.renderer.listen(this.button.nativeElement, 'click', ($event: any) => this.handleClick($event)); }
handleClick($event: any) { this.cancelClick(); // ... }}
3
第三方 event 实现
<button (once.click)="handleClick($event)">...</button>
网友评论