首页 > 解决方案 > 如何在 angular7 的整个模块中提供通用打字稿服务?

问题描述

我想

_findEpisodeService

在我的 app.module 中可用。所以我需要在我的 app.module 的 @NgModule 的 providers 数组中提供它。问题是我不知道该怎么做。请帮忙!

// Generic service
export class ServicestackService<T> {
  constructor(private _auth: AuthenticationService, private _router: Router) {
    this._client.onAuthenticationRequired = this.onAuthenticationRequired;
  }
}

// service.ts
const req = new FindEpisode();
const _findEpisodeService = new ServicestackService<FindEpisode>(this.auth, this.router);

// App.module.ts
@NgModule({
providers: [
 {provide: JsonServiceClient, useValue: new JsonServiceClient('/')}
 ],
})

标签: typescriptservicestackangular7

解决方案


推荐阅读