以下是我AppComponent
的代码 - 请注意我称之为AppPage
,因为它会在以后演变为“智能”组件:
import { Component } from '@angular/core';
import { AuthService } from '@app/core';
@Component({
selector: 'slctr-root',
template: `<router-outlet></router-outlet>`
})
export class AppPage {
constructor(private authService: AuthService) {
authService.handleAuthentication();
}
}
在WebStorm中,@Component
带有以下错误的下划线:Cannot resolve all parameters for AppPage in app.page.ts (?)
我的tsconfig.json
文件包含"emitDecoratorMetadata": true
和"lib": [ "es2017", "dom" ]
,且该应用确实构建正确。
我错过了什么?
更新:显示CoreModule
和AppModule
代码:
@NgModule({
imports: [ CommonModule ],
declarations: [LandingPageComponent],
providers: [
// App singleton services
AuthService
],
exports: [
// 3rd party libraries
// Components
LandingPageComponent
]
})
export class CoreModule {
// make sure CoreModule is imported only by one NgModule: the AppModule
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
if (parentModule) {
throw new Error('CoreModule is already loaded. Please import it in the AppModule only.');
}
}
}
@NgModule({
declarations: [
AppPage
],
imports: [
BrowserModule,
AppRoutingModule,
CoreModule
],
providers: [],
bootstrap: [AppPage]
})
export class AppModule {
}
更新:添加AuthService
代码:
import { Injectable } from '@angular/core';
import { environment } from '@env/environment';
import * as auth0 from 'auth0-js';
@Injectable()
export class AuthService {
auth0 = new auth0.WebAuth({
clientID: environment.auth0.clientId,
domain: environment.auth0.domain,
responseType: 'token id_token',
audience: environment.auth0.audience,
redirectUri: environment.auth0.redirectUri,
scope: 'openid email profile'
});
public static loggedIn(): boolean {
// Check whether the current time is past the access token's expiry time
return new Date().getTime() < JSON.parse(localStorage.getItem('expires_at'));
}
public login(): void {
this.auth0.authorize({});
}
public handleAuthentication(): void {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
window.location.hash = '';
// Set the time that the access token will expire at
localStorage.setItem('expires_at', JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime()));
localStorage.setItem('id_token', authResult.idToken);
// Route to
} else if (err) {
console.log(err);
}
});
}
}
答案 0 :(得分:0)
看起来这是一个已在Angular v5.1.0中修复的已知问题:https://github.com/angular/angular/issues/16382
更新,2017年12月7日:我确认,这是在v5.1.0中修复的