【发布时间】:2017-02-04 21:41:30
【问题描述】:
基本上我想要here 中描述的相同行为,但在指令中工作,因为我将在整个应用程序中使用。
到目前为止,我在指令中得到了这个:
@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;
}
}
第 1 步和第 2 步目前工作正常,我的问题出在第 3 步。我在哪里可以将我的函数绑定到点击函数上执行的事件的结尾(通常是 http 请求)?
【问题讨论】: