我试图在可观察对象完成后实现一个简单的回调,这是我的代码:
ngOnInit() {
this.propertyService
.getProperties()
.subscribe(
(data: ContentPropertyModel[]) => this.properties = data
);
this.status = 'active';
}
然而,状态在可观察对象运行之前发生了变化。关于在 observable 运行后如何更改 this.status 的任何想法?
最佳答案
将 this.status
移动到您的订阅处理程序:
ngOnInit() {
this.propertyService
.getProperties()
.subscribe(
(data: ContentPropertyModel[]) => {
this.properties = data
this.status = 'active';
}
);
}
关于Angular2 可观察回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42265182/