我是Angular的新手,实际上,每次我尝试为身份验证模块调用loadToken()函数时,都会收到此错误:
AppComponent.html:24 ERROR TypeError: Cannot read property 'split' of null
at JwtHelper.decodeToken (angular2-jwt.js:234)
at AuthenticationService.loadToken (authentication.service.ts:37)
..........
在解码令牌之前如何正确处理令牌?
loadToken(){
this.jwtToken=localStorage.getItem('token');
if(!this.jwtToken)
console.log("****************NULL TOKEN****************");
console.log(this.jwtToken);
let jwtHelper=new JwtHelper();
this.roles=jwtHelper.decodeToken(this.jwtToken).roles;
return this.jwtToken;
}