angular - Not able to bind click event in @Directive in angular4 -
i have simple directive this
import { directive, hostlistener, eventemitter, output } '@angular/core'; @directive({ selector: '[appappclick]' }) export class appclickdirective { @output() clickdirective: eventemitter<any> = new eventemitter(); constructor() { } @hostlistener('onclick') onclick() { debugger; this.clickdirective.emit(); } }
now, want trigger click event of component have placed directive this
<button type="button" class="btn btn-secondary" data-dismiss="modal" appappclick (clickdirective)="parentclick()"> proceed</button>
this component ts code
import { component } '@angular/core'; @component({ selector: 'app-root', templateurl: './app.component.html', styleurls: ['./app.component.css'] }) export class appcomponent { title = 'app'; parentfunc() { alert('parent function called'); } }
when placed debugger inside directives onclick() event, noticed event not getting called refrenced blog
@hostlistener('click',['$event']) onclick($event) { debugger; this.clickdirective.emit(); }
Comments
Post a Comment