数据请求同时带上loading效果
来源:7-3 什么是 Effects

sbura
2019-05-12
老师, 如果是一个表格请求数据, 他请求过程中要带有loading效果:
原始代码是这样的:
getData(): {
this.loading = true;
this.service.getData().toPromise().then(res:data[] => {
this.loading= false;
this.tabledata=res;
} )
}
如果是用effect改写:
@Effect()
data$: Observable<Action> = this.actions$.pipe(
ofType<actions.Load>(actions.LOAD),
switchMap(() =>
this.service.getData().pipe(
map(data=> new actions.LoadSuccessAction(data)),
catchError(err => of(new actions.LoadFailAction(JSON.stringify(err))))
)
)
);
loading的状态该怎么根据数据请求来变化呢?
写回答
1回答
-
loading 一般可以放在 state 中,然后在reducer对应的状态改变 state 中的 loading 值就行了
012019-05-14
Angular打造企业级协作平台,让你在Angular领域中出类拔萃
全网首个介绍官方 Material 组件库用法与 Redux 在 Angular 中的应用
998 学习 · 536 问题
相似问题