typescript - 如何在 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('/')}
],
})
解决方案
推荐阅读
- c++ - C++ 使用带有位 OR 运算符的枚举
- javascript - 按下选项卡按钮或在状态列中输入“已分配”值时如何自动发送电子邮件
- xamarin - Xamarin.forms android 更改软件后退按钮布局背景颜色
- html - How to do styling on HTML tags contained within the hyperlink tag
- python - peewee.OperationalError:没有这样的功能:json
- sql-execution-plan - Apache Druid 原生查询解释计划
- python - Numpy/Python 使用跳转按百分比拆分数组
- javascript - JS insertAdjacentHTML() 被完全忽略
- java - 素数检查方法不接受布尔返回值
- rust - 为什么要定义具有单元类型的单个私有字段的结构?