0

i got a Problem. I want a global Service. I found this: Link. It works but i want after initialized my component an event what is called after my component is bootstrapped.

Anyone know this event?

Lyror

Update

yes i want to do that:

import {GlobalService} from './GlobalService';
import {Component, provide, Injector, ComponentRef} from 'angular2/core';
import {bootstrap}        from 'angular2/platform/browser';
import {HTTP_PROVIDERS} from 'angular2/http';
import {appInjector} from './app.injector';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS,
    LocationStrategy, HashLocationStrategy} from 'angular2/router';
import {AppComponent}     from './app.component';

bootstrap(AppComponent, [
    ROUTER_PROVIDERS,
    provide(LocationStrategy, { useClass: HashLocationStrategy }),
    HTTP_PROVIDERS,
    GlobalService
]).then((appRef: ComponentRef) => {

    var injector = appInjector(appRef.injector);
    var appComp: AppComponent = injector.get(AppComponent);

    appComp.init();
});

But i get two Errors:

Unhandled Promise rejection: appComp.init is not a function ; Zone: ; Task: Promise.then ; Value: TypeError: appComp.init is not a function

Error: Uncaught (in promise): TypeError: appComp.init is not a function

Community
  • 1
  • 1
Lyror
  • 3
  • 1

1 Answers1

0

The bootstrap function return a promise. The provided callback at this level is called when the component is bootstrapped:

bootstrap(AppComponent).then((compRef:ComponentRef) => {
  // Do something after the component is bootstrapped
  var comp = compRef.instance;
  comp.init();
});
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360