问题
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'));
}
I then changed it into this:
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.
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.
Any ideas?
回答1:
You need to complete the stream.
return this.store
.select('configuration')
.do(data => console.log(data))
.map((data: any) => data.pages.filter(page => page.parent === 'home'))
.first()
来源:https://stackoverflow.com/questions/45099626/angular-4-resolve-not-completed-when-using-ngrx