为什么Angular解析器在使用of()返回可观察时不返回任何数据,而在使用of()时返回.pipe(delay(1000))

时间:2019-11-02 23:28:54

标签: angular rxjs ngxs

我的问题就是标题中的问题。我不完全了解为什么使用n创建返回的对象时,Angular解析器为什么不返回(不解析)任何数据,但是使用var sumEvery5th = function(n) { let sum = 0; for (let i = 5; i <= n; i += 5) { sum += i; }; return sum; } console.log(sumEvery5th(10)); // 5 + 10 = 15 console.log(sumEvery5th(18)); // 5 + 10 + 15 = 30

时却起作用

举个简单的例子: 解析器:

of([...someData])

of([...someData]).pipe(delay(1000)调用 resolve( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): | Schedule.FetchAllSportTypesSuccess | Schedule.FetchAllSportTypesFailed | Observable<Schedule.FetchAllSportTypesSuccess | Schedule.FetchAllSportTypesFailed> | Promise<Schedule.FetchAllSportTypesSuccess | Schedule.FetchAllSportTypesFailed> { this.store.dispatch(new Schedule.FetchAllSportTypes()); const responseOK: Observable<Schedule.FetchAllSportTypesSuccess> = this.actions$.pipe(ofAction(Schedule.FetchAllSportTypesSuccess)); const responseError = this.actions$.pipe( ofAction(Schedule.FetchAllSportTypesFailed), tap(() => this.router.navigate([''])) ); return race(responseOK, responseError).pipe(first()); } 方法:

this.store.dispatch(new Schedule.FetchAllSportTypes())

fetchAllSportTypes的实现如下时,解析器不返回任何数据,而是一直等待:

fetchAllSportTypes(): Observable<SportType[]>{

}

但是当实现如下时,解析器确实可以按预期工作:

fetchAllSportTypes(): Observable<SportType[]>

0 个答案:

没有答案