При попытке добавить сервис идентификации, но он падает, токен получен от API. Любая помощь приветствуется.
app.module:
import { AuthGuard } from './auth-guard.service';
@NgModule({
... providers: [AuthGuard] })
AuthGuardService:
import { JwtHelper } from 'angular2-jwt';
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private jwtHelper: JwtHelper, private router: Router) {
}
canActivate() {
const token = localStorage.getItem('jwt');
if (token && !this.jwtHelper.isTokenExpired(token)) {
return true;
}
this.router.navigate(['login']);
return false;
}
}
AppRouting:
{ path: 'account', component: AccountComponent, canActivate: [AuthGuard] }
Ошибка:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[AuthGuard -> JwtHelper]:
StaticInjectorError(Platform: core)[AuthGuard -> JwtHelper]:
NullInjectorError: No provider for JwtHelper!
Error: StaticInjectorError(AppModule)[AuthGuard -> JwtHelper]:
StaticInjectorError(Platform: core)[AuthGuard -> JwtHelper]:
NullInjectorError: No provider for JwtHelper!