1

In my Angular 2 project, I am using 2 different services in a single component. They both have required Injector parameters. The issue I am trying to resolve is that both DI parameters use the same name, but I do not know how to format my component providers to specify the values for each unique service.

For example:

Service1 constructor: @Inject('page') public page: string

Service2 constructor: @Inject('page') public page: string

In my component, I set the providers as follows:

@Component({
...
providers: [
Service1,
{provide: 'page', useValue: 'test1'},
Service2,
{provide: 'page', useValue: 'test2'}
]
...})

I want to pass the unique 'page' values to each service, but both services end up getting the value 'test2' for the DI parameter.

How can I write my component providers in a way that will pass the right parameter values to their associated service?

0 Answers0