In my directive I added a event listener like this:
//this is works by default
this.el.nativeElement.onfocus = function(e){
that.warpper.classList.add("show");
}
//this is works not works default
this.el.nativeElement.onblur = function(e){
that.warpper.classList.remove("show");
}
then I added the following line to directive:
this.renderer.listen(this.el.nativeElement, 'onblur', ( event ) => console.log(event) );
after added the above, this is start works:
this.el.nativeElement.onblur = function(e){
that.warpper.classList.remove("show");
}
As well I am not getting any console at:
this.renderer.listen(this.el.nativeElement, 'onblur', ( event ) => console.log(event) );
here is my directive code :
import { Directive, ElementRef, Renderer2 } from '@angular/core';
import { SharedDatasService } from '../shared/service/shared-datas.service';
@Directive({
selector: '[fieldCleaner]'
})
export class FieldCleanerDirective {
warpper:Element;
link:any;
constructor(private el:ElementRef, private renderer:Renderer2,
private sharedData:SharedDatasService) {
this.el.nativeElement.onfocus = function(e){
that.warpper.classList.add("show");
}
this.el.nativeElement.onblur = function(e){
that.warpper.classList.remove("show");
}
this.renderer.listen(this.el.nativeElement, 'onblur', ( event ) => console.log(event) );
}
}
How can I understand the above behaviors? or what is wrong with my code?