函数在Angular2中被误解为属性?

函数在Angular2中被误解为属性?,angular,Angular,开始用Angular2做实验。在调用this.auth.isLoggedIn()时,错误出现在该块中。我得到一个属性“isLoggedIn”在类型“AuthService”上不存在。错误。为什么函数调用被解释为属性访问 import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { CanActivate } from '@angular/router'; import

开始用Angular2做实验。在调用
this.auth.isLoggedIn()
时,错误出现在该块中。我得到一个
属性“isLoggedIn”在类型“AuthService”上不存在。
错误。为什么函数调用被解释为属性访问

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { CanActivate } from '@angular/router';

import { AuthService } from './auth.service';

export class AuthGuard implements CanActivate {

  constructor(private auth: AuthService, private router: Router) {}

  canActivate() {
    if(!this.auth.isLoggedIn()) {
      this.router.navigate[''];
      return false;
    }
  }
}
以下是正在注入的服务:

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

@Injectable()
export class AuthService {
  private loggedIn:boolean = false;

  constructor(private router: Router) {
    this.loggedIn = !!localStorage.getItem('auth_token');
  }

  login(email:string, password:string):void {
    localStorage.setItem('auth_token', 'x');
    this.loggedIn = true;
  }

  logout():void {
    localStorage.removeItem('auth_token');
    this.loggedIn = false;
  }

  isLoggedin():boolean {
    return this.loggedIn;
  }
}

请将服务的方法签名从
isLoggedin():boolean
更改为
isLoggedin():boolean

请将服务的方法签名从
isLoggedin():boolean
更改为
isLoggedin():boolean

isLoggedin()(方法名)isLoggedin().isLoggedin()(方法名)isLoggedin().Crap。看到这一点我感到很尴尬没问题,我在宗教上让自己难堪。废话。看到这一点我感到很尴尬没问题,我在宗教上让自己难堪。