Understand OpaqueToken in Angular

InstructorPascal Precht

Share this video with your friends

Send Tweet

When using provider string tokens, there’s a chance they collide with other third-party tokens. Angular has with the concept of opaque tokens, that allow us to make whatever token we use unique, so we don’t run into collision problems. In this lesson we’ll explore how they work.

Brian
~ 8 years ago

What about using a Symbol

jason huang
~ 8 years ago

If we change the third-party to also use an opaque token How does Angular know which 'API_URL' token to use ?

<pre><code> providers: [ DataService, ConsoleService, { provideL LogDebugger, useFactory: (consoleService) => { return new LogDebugger(consoleService, true); }, deps: [ConsoleService] }, { provide: API_URL , useValue: 'http://localhost:4200/api'; }, THIRD_PARTY_PROVIDERS ] </code></pre>
Erik Nijland
~ 7 years ago

This is deprecated since Angular 4. They're recommending a switch to InjectionToken.