我正在尝试为我的路线创建 auth Guard 服务。在此服务中,我需要注入我用来返回当前登录用户的 UserAccountService。
这是我的后卫:
import { Injectable, Inject } from '@angular/core';
import { CanActivate } from '@angular/router';
import { UserAccountService } from '../';
@Injectable() export class ClaimsGuardService implements CanActivate
{
constructor(private user: UserAccountService) { }
canActivate(route, state) {
return true;
}
}
UserAccountService
工作正常注入组件,它包含在我的app.module
:
providers: [
provideInterceptorService([
new ServerURLInterceptor(new CookieService())
]),
ClaimsGuardService,
CookieService,
UserAccountService,
],
其他服务,例如CookieService
,Http
等,注入就好了,但是UserAccountService
有这个问题。
下面是服务的定义:
@Injectable()
export class UserAccountService {
private currentUser: any = {};
constructor(private cookieService: CookieService, private http: InterceptorService) {
}
}