Is it possible to define a condition in the template based on which a click handler is attached?
For instance, the closest I can get is evaluating a condition at the
There is no way to do enable/disable bindings.
It's possible to do that imperatively
@ViewChild('.user') aUser:ElementRef;
clickHandler(event) {
console.log(event);
}
_clickHandler = this.clickHandler.bind(this);
ngAfterViewInit() {
this.aUser.nativeElement.addEventListener('click', this._clickHandler);
}
to unsubscribe use
this.aUser.nativeElement.removeEventListener('click', this._clickHandler);
See also Dynamically add event listener in Angular 2