Angular 2 Typescript - 承诺匿名函数

时间:2016-08-02 15:30:42

标签: javascript typescript angular angular-promise es6-promise

我正在使用登录API并遇到了这个问题,我标记了一条评论:

this.service.login(this.user).then(res => this.api.controlData(res))
.then(e => function(e){
    console.log(e); // NOTHING HAPPENS HERE

    if(!e){
       console.log(this.getMsg());
    }else{
       this.router.navigate(['dashboard']);
    }
}).catch (function (error) {
    console.log(error);
});

所以我的匿名函数没有任何反应 然而,这确实有效:

this.service.login(this.user).then(res => this.api.controlData(res))
.then(e => this.functionAnonymeMaisenFaiteNon(e))
.catch (function (error) {
    console.log(error);
 });

 private functionAnonymeMaisenFaiteNon(e: boolean){
    if(!e){
       console.log(this.getMsg());
    }else{
       this.router.navigate(['dashboard']);
    }
 }

我不太确定匿名函数有什么不同。

0 个答案:

没有答案
相关问题