I have a global js variable defined below (@Url is an ASP.Net MVC html helper it will get converted to a string value):
You need to update the file that bootstraps your application to export a function:
import {bootstrap} from '...';
import {provide} from '...';
import {AppComponent} from '...';
export function main(rootVar) {
bootstrap(AppComponent, [
provide('rootVar', { useValue: rootVar })
]);
}
Now you can provide the variable from the index.html file this way:
Then you can inject the rootVar into components and services this way:
import { Component, Inject} from '@angular/core';
@Component({
selector: 'home-comp',
templateUrl: '../Home/Root'
})
export class HomeComponent {
constructor(@Inject('rootVar') rootVar:string ) { }
}