Angular core providers like PLATFORM_ID

  angular, angular-providers

In value-based providers (tokens), we have something like this (in the module):

const CONFIG = 'CONFIG';
providers: [
    {
        provide: CONFIG,
        useValue: myConfigObj,
    },

Because we defined the provider in module, in a service we can do this:

constructor(@Optional() @Inject(CONFIG) config) {
    console.log(config);
}

But when we want to access PLATFORM_ID like this:

constructor(@Inject(PLATFORM_ID) private platformId) {

We don’t define PLATFORM_ID in the module’s provider. In which module this is defined? And what is the useValue ?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.