0

I was wondering how exactly works the onInit, especially when calling some services. Here is my main component :

@Component({
    selector: "app",
    templateUrl: "app/app.html",
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig(){
...
}
export class AppComponent implements OnInit {
    constructor (private _fooManager: FooManager) {}

    ngOnInit() {
        this._fooManager.fetchAllFoos() // Do a web service call to fetch some data and store them inside the FooManager
    }
}

(FooManager's injection comes from my bootstrap.ts)

then all my other components are using the FooManager's data (especially in their templates). I was wondering if I had to check the status of the call done in the fetchAllFoos or if the ngOnInit gives any guarantees that the values are fully loaded ?

If not, I guess one solution would be to give a promise back and then check the promise status.

Scipion
  • 11,449
  • 19
  • 74
  • 139

1 Answers1

1

ngOnInit() doesn't do anything special except being called at some point after the component was initialized.

What you want is probably something like What is the correct way to share the result of an Angular 2 Http network call in RxJs 5?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567