javascript - emit triggers a method in angualr2 and then how to get the result of this promise
習慣沉默
習慣沉默 2017-05-27 17:44:24
0
1
809

Now I have written a direactive to replace the click operation. After clicking, the button is disabled. For example, click is a method to call login, and the button is restored after the promise of the login service ends.
Now you can simulate click and disable the button, but you cannot get the result of promise. Is there any good method?

//directive (大概的代码)

@Output() czClick  = new EventEmitter();
@HostListener("click",["$event"])
    onClick(e){
        this.renderer.setElementAttribute(this.element.nativeElement,'disabled','true');
        this.czClick.emit(e);
      
    }
//html
<button cz-click (czClick)="login()">登录</button>

Mainly this.czClick.emit(e); If the promise result of login cannot be obtained here, the effect of the button cannot be modified in the end state.

Ask for advice 0-0

習慣沉默
習慣沉默

reply all(1)
phpcn_u1582

(czClick)="login($event)"吧?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template