类型既不是“无效”。也没有任何'必须返回一个值

时间:2017-10-22 14:10:57

标签: angular

我正在尝试为登录实现身份验证并获得以下错误:

A function whose declared type is neither 'void' nor 'any' must return a value.

代码:

this.isLoggedIn = false;

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean>{
    let url: string = state.url;
    return this.checkLogin(url);
}

checkLogin(url: string): Observable<boolean> {

    this.authService.isUserLoggedIn()
        .map(
           data => {
        // getting true or false as  loggedIn value
            this.isLoggedIn = data.loggedIn;


            if (this.isLoggedIn) {       
              return true;
            }

            // Redirect on home page with login popup.
            this.router.navigate(['/']);

            return false;

         });
}

无法弄清问题是什么。

0 个答案:

没有答案