-
-
Notifications
You must be signed in to change notification settings - Fork 86
Custom configuration
Michael Hladky edited this page Apr 20, 2018
·
4 revisions
There is a Service called StarRatingConfigService
which you can use to configure all star rating conponents.
You can do so by overriding the StarRatingConfigService
in your modules providers section.
Create a new service by using the cli ng generate service pathToFolder/serviceName --module=pathToModule/moduleName.ts
Extend StarRatingConfigService
and override some properties:
@Injectable()
export class CustomConfigService extends StarRatingConfigService {
constructor() {
super();
this.numOfStars = 3;
this.staticColor = 'positive';
}
}
In your module implement the needed providers:
@NgModule({
imports: [
[...]
StarRatingModule.forRoot()
],
[...]
providers: [
{
provide: StarRatingConfigService, useClass: CustomConfigService
}
]
})
export class AppModule {}
Create a new service by using the cli ng generate service pathToFolder/serviceName --module=pathToModule/moduleName.ts
Extend StarRatingConfigService
and override some properties:
@Injectable()
export class CustomConfigService extends StarRatingConfigService {
constructor() {
super();
this.numOfStars = 3;
this.staticColor = 'positive';
}
}
In your feature module implement the needed providers:
@NgModule({
imports: [
[...]
StarRatingModule.forRoot()
],
[...]
providers: [
{
provide: StarRatingConfigService, useClass: CustomConfigService
}
]
})
export class FeatureModule {}
There is also the possibility to override is in the components providers section.
@Component({
selector: 'my-component',
template: `
<h2>Custom local config</h2>
<star-rating></star-rating>`,
providers: [
{
provide: StarRatingConfigService, useClass: CustomLocalConfigService
}
]
})
export class CustomLocalConfigComponent {
}