我的问题就是标题中的问题。我不完全了解为什么使用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[]>