-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.ts
42 lines (37 loc) · 1.14 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { ModuleWithProviders, NgModule, Provider } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ResourceHandler } from '@ngx-resource/core';
import { ResourceHandlerHttpClient } from './src/ResourceHandlerHttpClient';
export * from './src/ResourceHandlerHttpClient';
export interface IResourceModuleConfig {
handler?: Provider;
}
@NgModule()
export class ResourceModule {
/**
* For root
* @param {IResourceModuleConfig} config
* @return {ModuleWithProviders}
*/
static forRoot(config: IResourceModuleConfig = {}): ModuleWithProviders {
return {
ngModule: ResourceModule,
providers: [
config.handler || {provide: ResourceHandler, useClass: ResourceHandlerHttpClient, deps: [HttpClient]}
]
};
}
/**
* For child
* @param {IResourceModuleConfig} config
* @return {ModuleWithProviders}
*/
static forChild(config: IResourceModuleConfig = {}): ModuleWithProviders {
return {
ngModule: ResourceModule,
providers: [
config.handler || {provide: ResourceHandler, useClass: ResourceHandlerHttpClient, deps: [HttpClient]}
]
};
}
}