变量返回true,但函数返回false

时间:2019-12-28 02:53:47

标签: javascript

private hasAccess() {
  let access = false;
  this.login.hasCookie(this.cookieService.get('login')).subscribe(hasCookie => {
    if (hasCookie === 1) {
      this.login.getCookie().subscribe(cookieFromServer => {
        if (cookieFromServer === this.cookieService.get('login')) {
          access = true;
          console.log(access);
        }
      });
    }
  });
  return access;
}

第8行上的console.log返回true,但是我的函数返回false。这是相同的变量。为什么返回假?应该是真的!

0 个答案:

没有答案