I have a global constants like root directory that I want every component to have access to. In another stackoverflow question the answer was to create a constants class and imp
To answer your questions:
All components using the Constants class will need to import your constants file.
In order to use the Constants class you need to inject it into the constructor of any consuming components, removing the injector.get() function from random.component.ts like so:
export class App {
constructor(constants: Constants) {
this.url = constants.root_dir;
}
}
You may also decorate your constant class as an @Injectable
and @Inject
it into the constructor of your component.
Here is a working plunker.
It is beneficial to bootstrap the shared constants at the app level so that only one instance of the class is created and shared among all components.