Basically I want the same behavior described here but working in a directive, since I am going to use throughout my app.
So far I got this in my directive:
@Directive({
selector: '[asyncLoader]'
})
export class ActionAsyncLoader {
@Input('asyncLoader') asyncLoader: string;
...
//1 - save the text for further use.
ngOnInit(){
this.text = this.elementRef.nativeElement.innerHTML;
}
//2 - change the text when "click" is triggered
@HostListener('click', ['$event.target']) onClick(btn) {
btn.innerHTML = 'Loading';
}
//3 - change text back to the normal value
onCallbackAsync(obj){
this.elementRef.nativeElement.innerHTML = this.text;
}
}
Steps 1 and 2 are currently working fine, my problem is in the step 3. Where Can I bind my function to the end of event executed on click function(Usually http requests)?