typescript - Issue with globally visible service in Angular 2 -
i tying make service, visible without importing in component.
my bootstrap function:
export function main(initialhmrstate?: any): promise<any> { console.log(app_providers); return bootstrap(app, [ ...platform_providers, ...env_providers, ...app_providers ]) .then(decoratecomponentref) .catch(err => console.error(err)); }
app providers definition:
export * './app.component'; export * './user.state'; export * './app.service'; import { userstate } './user.state'; import { appstate } './app.service'; // application wide providers export const app_providers = [ userstate, appstate ];
and can not call in components constructor
constructor( private userstate: userstate ) {}
how can fix problem?
either importing or using string token or opaquetoken
, `@inject()
export const app_providers = [ {provide: 'userstate', useclass: userstate}, appstate ];
constructor(@inject('userstate') private userstate: ) {}
Comments
Post a Comment