【发布时间】:2018-04-19 13:48:27
【问题描述】:
我已经使用ngrx/effects 开发了angular2 应用程序来进行http 调用。我使用GIT 作为参考应用程序。一旦响应来自 http,我就无法在屏幕上显示它。它显示[object Object]。这是我的代码。
链接到component.html的HTML页面
<div class="container">
<div class="left-container cf">
<mat-tab-group>
<mat-tab label="Configuration">{{jsons}}</mat-tab>
<mat-tab label="Captured Output">
</mat-tab>
</mat-tab-group>
</div>
</div>
组件.ts
export class ExperimentDetailsComponent implements OnInit {
jsons: Observable<any>;
isLoading: Observable<any>;
constructor(
private store: Store<fromStore.State>
) {
this.isLoading = store.select(fromStore.getIsLoading);
this.jsons = store.select(fromStore.getJson);
console.log(this.jsons)
}
ngOnInit() {
this.store.dispatch(new jsonAction.GetJson());
// this.jsons = this.store.select(fromStore.getJson);
}
}
Effects.ts
export class GetJsonEffects {
@Effect() json$ = this.actions$.ofType(Act.GET_JSON)
.map(toPayload)
.withLatestFrom(this.store$)
.mergeMap(([ payload, store ]) => {
return this.http$
.get(`http://localhost:4000/data/`)
.map(data => {
return new Act.GetJsonSuccess({ data: data })
})
.catch((error) => {
return Observable.of(
new Act.GetJsonFailed({ error: error })
);
})
});
constructor(
private actions$: Actions,
private http$: HttpClient,
private store$: Store<fromStore.State>
) {}
}
【问题讨论】:
-
你的代码中哪一部分与
[Object Object]相关。它在哪里显示?预期的行为是什么? -
如果要显示json对象可以使用
json管道:{{jsons|json}} -
感谢您的回复。如果我使用 {{jsons | json}} 我收到错误 - 错误类型错误:将循环结构转换为 JSON
标签: html angular rest ngrx-effects