2017-08-08 79 views
0

所以在我的/xyz.component.ts中,我從/user.ts調用了resetPassword方法。在LoopBack文檔中它說:如何使用默認用戶模型實現帶FireLoop的resetPassword?

調用User.resetPassword最終會發出resetPasswordRequest事件並創建一個臨時訪問令牌。

但是,如何捕捉事件?如果我嘗試應用.on('resetPasswordRequest',()=> {....}),它會告訴我UserApi沒有'on'。


/xyz.component.ts

private resetPassword(){ 
 
    this.userApi.resetPassword({email: this.userName}).subscribe((data : any)=>{ 
 
     console.log(data); 
 
    },(error : any) => { 
 
     this.error = error; 
 
     } 
 
    ); 
 
    console.log("error: " , this.error); 
 
    }

/user.ts

public resetPassword(options: any, customHeaders?: Function): Observable<any> { 
 
    let _method: string = "POST"; 
 
    let _url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + 
 
    "/Users/reset"; 
 
    let _routeParams: any = {}; 
 
    let _postBody: any = { 
 
     options: options 
 
    }; 
 
    let _urlParams: any = {}; 
 
    let result = this.request(_method, _url, _routeParams, _urlParams, _postBody, null, customHeaders); 
 
    return result; 
 
    }

回答

0

MROALI非常善良的幫我解決了我在GitHub上的問題。 所以,你需要怎樣做才能趕上「resetPasswordRequest」事件在編輯您的用戶模型的構造(或extendend用戶模型,如果你不使用默認的),像這樣:

constructor(public model: any) { 
    model.on('resetPasswordRequest', function (info:any) { 
    console.log("do something"); 
    }) 
    } 
相關問題