尝试使用rxjs链实现刷新或轮询。
ngOnInit() {
const id$ = this.route.params;
id$.subscribe((params: Params) => {
this.id = params['id'];
this.userService.getUser(params['id']).subscribe(this.getUserSubject$));
}
this.getUserSubject$
.flatMap(user =>
Observable.forkJoin(this.userService.getAddress(user), this.userService.isActive(user),
(address, isActive) => {
return _.assign({}, user, address, {isActive: isActive});
}
)
)
.subscribe(user => {
this.user = user
}, err => this.error(err));
}
refresh($event) {
this.userService.getUser(this.id).subscribe(this.getUserSubject$);
}
在刷新调用时,不会调用getUserSubject $链。 它只在ngOnInit上调用一次。 如何将数据推送到getUserSubject $,以便更新用户。 为什么可观察链不会从刷新中调用。