Angular2可观察到的回调

rhy*_*lay 3 observable angular

我试图在可观察对象完成后实现一个简单的回调,这是我的代码:

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

但是,状态在可观察运行之前已更改。关于如何在可观察到的运行后如何更改this.status的任何想法?

pix*_*its 5

移至this.status您的订阅处理程序:

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