我不断收到以下错误:Static member is not accessible此时:
验证服务
export class AuthService {
public static get isLoggedIn() {
const user = JSON.parse(localStorage.getItem('user'));
return (user !== null &&
((user.emailVerified === false && user.providerData[0].providerId === 'facebook.com') ||
((user.emailVerified !== false))));
}
}
Run Code Online (Sandbox Code Playgroud)
navbar.component.html
<nav *ngIf="!authService.isLoggedIn" class="navbar navbar-expand-lg navbar-dark" data-navbar="smart"></nav>
Run Code Online (Sandbox Code Playgroud)
navbar.component.ts
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html'
})
export class NavbarComponent implements OnInit {
constructor(
private authService: AuthService
) {}
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
您不需要注入AuthService,只需在组件中创建一个属性即可从中获取值AuthService.isLoggedIn
export class NavbarComponent implements OnInit {
constructor(){}
get isLoggedIn () {
return AuthService.isLoggedIn
}
}
Run Code Online (Sandbox Code Playgroud)
模板
<nav *ngIf="!isLoggedIn" class="navbar navbar-expand-lg navbar-dark" data-navbar="smart">
</nav>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |