next
两次,它将起作用。像这样:
getTickets() {
this._subject.next(this.getTicketsFromCache());
this.serverService.getAllTickets()
.subscribe((getAllTicketsResponse: GetAllTicketsResponse) => {
this._tickets = getAllTicketsResponse.Result.tickets;
this._subject.next(this._tickets);
});
return this._subject;
}
但是我的问题是组件如何才能知道这是来自缓存?我需要在刷新时显示加载图标,并在结束时将其隐藏。我该怎么办?
答案 0 :(得分:2)
与其传递裸值传递对象{ value, isLoading }
getTickets() {
this._subject.next({
value: this.getTicketsFromCache(),
isLoading: true,
});
this.serverService.getAllTickets()
.subscribe((getAllTicketsResponse: GetAllTicketsResponse) => {
this._tickets = getAllTicketsResponse.Result.tickets;
this._subject.next({
value: this._tickets,
isLoading: false,
});
});
return this._subject;
}
并处理组件中的其他逻辑