如何解决以下错误
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包,并在提供程序中添加了[[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 {}
InjectionToken
以便配置服务。您还需要在AppModule中提供此InjectionToken
。请参考软件包的文档,或尝试在服务的源代码中找到InjectionToken的导出名称。