使用ngrx时Angular 4解析未完成 [英] Angular 4 resolve not completed when using ngrx

查看:60
本文介绍了使用ngrx时Angular 4解析未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在应用程序的解析中使用ngrx,由于某种原因,它无法正常工作.

I'm trying to use ngrx in a resolve in my app and for some reason it's not working.

这是我以前通过在解析路径中使用简单的服务来获取它的方式:

This is how I got it previously, using a simple service in my resolve route:

resolve() {
  return this.service
    .getData()
    .map(data => data.pages.filter(page => page.parent === 'home'));
}

然后我将其更改为:

resolve() {
  this.store.dispatch(new LoadConfigAction());
  return this.store
    .select('configuration')
    .do(data => console.log(data))
    .map((data: any) => data.pages.filter(page => page.parent === 'home'));
}

我在控制台中获取了数据,因此正在检索数据,但是解决的过程显然还没有完成,因此我的导航不会发生.

I get data in my console, so data is being retrieved, but the resolved is apparently not finishing, so my navigation does not happen.

我想知道this.store的返回类型是否与我的服务中的Observable不同,但是我有点迷茫.

I'm wondering if maybe the return type from this.store is not the same as an Observable from my service, but I'm a bit lost.

有什么想法吗?

推荐答案

您需要完成流.

return this.store
    .select('configuration')
    .do(data => console.log(data))
    .map((data: any) => data.pages.filter(page => page.parent === 'home'))
    .first()

这篇关于使用ngrx时Angular 4解析未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆