【问题标题】:StaticInjectorError(AppModule) Service -> InjectionToken error in AngularStaticInjectorError(AppModule) Service -> Angular 中的 InjectionToken 错误
【发布时间】:2020-05-19 15:51:26
【问题描述】:

如何解决以下错误

 AppComponent.html:9 ERROR Error: StaticInjectorError(AppModule)[OzaAuthService -> InjectionToken oza.config.angular]: 
  StaticInjectorError(Platform: core)[OzaAuthService -> InjectionToken oza.config.angular]: 
    NullInjectorError: No provider for InjectionToken oza.config.angular!

AuthService.ts :在 AuthService 中调用自定义“oza 包”。

import { OzaAuthService } from '@oza/oza-angular';

@Injectable({
  providedIn: 'root'
})

export class AuthService {
  _accessToken: string;
  constructor(private ozaAuthService: OzaAuthService) {
    console.log('ozaAuthService');
    this.$getAccessToken().subscribe(token => {
      this._accessToken = token;
    });
  }

  public getAccessToken(): string {
    return this._accessToken;
  }

在 App.module.ts 中导入 oza 包并在 provider 中添加 OzaAuthService 但仍然报错。

import { OzaAuthService} from '@oza/oza-angular';

 @NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
   imports: [
    BrowserModule,
    NgbModule,
    // router
    RouterModule.forRoot(routes),
    StoreModule.forRoot({}),
    })
  ],
  exports: [
    HttpClientModule
  ],
  providers: [
   **OzaAuthService**
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  bootstrap: [AppComponent]
})
export class AppModule {}

【问题讨论】:

  • 有什么更新吗?看我的回答

标签: angular angular-ui-router node-modules


【解决方案1】:

查看错误,似乎OzaAuthService 需要一个名为oza.config.angularInjectionToken 来配置服务。您还需要在 AppModule 中提供此 InjectionToken。要么参考包的文档,要么尝试在服务的源代码中找到 InjectionToken 的导出名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2019-05-24
    • 2018-08-18
    相关资源
    最近更新 更多