无法在app.page.ts(?)中解析AppPage的所有参数

时间:2017-11-29 16:27:24

标签: angular typescript angular-cli webstorm tsconfig

以下是我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" ],且该应用确实构建正确。

我错过了什么?

更新:显示CoreModuleAppModule代码:

@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);
      }
    });
  }
}

1 个答案:

答案 0 :(得分:0)

看起来这是一个已在Angular v5.1.0中修复的已知问题:https://github.com/angular/angular/issues/16382

更新,2017年12月7日:我确认,这是在v5.1.0中修复的