Seems that Angular 6 (4+?) requires token objects to be unique in order for the DI to work. Yet I want to use a dynamic token, to be provided from template html code, which will allow my new directive to resolve a service by name.
Currently the code:
this.service = this.injector.get(new InjectionToken<IServiceRef>(tokenName));
Fails with:
Error: StaticInjectorError(AppModule)[InjectionToken the_token_name]:
When I replaced my code with the old depricated (in angular 4) Injector.get function, it works okay, because the injector compares names (and I do provide the service in the view by that name...). However with the new DI I am not able to achieve what I want.
So, how to tackle?