无法解析服务参数。这将成为Angular 6.x中的错误

时间:2018-10-08 06:52:12

标签: angular angular-cli

当我构建具有基本抽象类的Logging库时,我正在警告。在检查了这里类似的问题后,大多数人只是说我应该在已经完成的基类中删除@Injectable。顺便说一句,我的类依赖项全部使用Inject,因为它们都是在InjectionTokens中创建的LoggingModule.forRoot()

logging.module.ts

@NgModule({
  declarations: [],
  imports: [],
  providers: [],
  exports: []
})
export class LoggingModule {

  public static forRoot(
    appName: string,
    customLogger: Provider,
    customLoggerDeps: Provider[] = [],
    filteredLogLevels: Array<LogLevel | string> = [],
    filterStrategies: Array<
      (logLevel: LogLevel | string, filter: LogLevel | string) => boolean
      > = []
  ): ModuleWithProviders {
    return {
      ngModule: LoggingModule,
      providers: [ // provide injection tokens here based from parameters 
      ]
    };
  }
}

logger.ts

export abstract class Logger {
    // abstract method declarations here
}

CustomLogger.ts

@Injectable()
export class CustomLogger extends Logger {
  constructor(
    @Inject(APP_NAME_TOKEN) protected appName: string,
    @Optional()
    @Inject(FILTER_STRATEGIES)
    protected filterStrategies: Array<
      (logLevel: LogLevel | string, filter: LogLevel | string) => boolean
    >,
    @Optional()
    @Inject(FILTERED_LOG_LEVELS)
    protected filteredLogLevels: Array<LogLevel | string>
  ) {
    super(appName, filterStrategies, filteredLogLevels);
  }
}

我有点困惑,为什么角度不知道如何注入这些代币。任何帮助将不胜感激。

通过CLI使用Angular 6.1的方式

0 个答案:

没有答案