为什么service [@Injectable()]保持侦听功能的角度。?

时间:2018-04-11 11:21:58

标签: angular angular-services

我只是检查用户是否loggedin来自服务,但是为什么它一直在听功能。?

loggedin(){
  const adminvalue = localStorage.getItem('user')
  console.log(adminvalue)
  if(adminvalue){
    return true
  }
  else {
    return false
  }
}

adminvalue在控制台中保持打印。

为什么选择路由到检查页面。?

HTML

<button (click)="login()" *ngIf="!service.loggedin()">Login</button>
<button (click)="logout()" *ngIf="service.loggedin()">Logout</button>

stackblitz console

0 个答案:

没有答案