Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Observable Callback

Im trying to implement a simple callback once an observable has finished, here is my code:

ngOnInit() {
    this.propertyService
    .getProperties()
    .subscribe(
        (data: ContentPropertyModel[]) => this.properties = data
    );
    this.status = 'active';
}

However the status is changed before the observable runs. Any ideas on how i can changes the this.status after the observable runs?

like image 806
rhysclay Avatar asked Sep 12 '25 06:09

rhysclay


1 Answers

Move this.status to your subscribe handler:

ngOnInit() {
    this.propertyService
    .getProperties()
    .subscribe(
        (data: ContentPropertyModel[]) => {
            this.properties = data
            this.status = 'active';
        }
    );
}
like image 116
pixelbits Avatar answered Sep 14 '25 23:09

pixelbits