search

Home  >  Q&A  >  body text

javascript - emit triggers a method in angualr2 and then how to get the result of this promise

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

習慣沉默習慣沉默2764 days ago812

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-27 17:46:24

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

    reply
    0
  • Cancelreply