77yf77yf77yf

angular resolver 给 ActivatedRoute 传了内部数据为空(但本身不为空)的对象

  •  
  •   77yf77yf77yf · Apr 23, 2024 · 1210 views
    This topic created in 758 days ago, the information mentioned may be changed or developed.

    Resolver: export const homeDataFetchGuard = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Response<Array<DisplayAnime>>> => { return inject(AnimeService).getUpdAniAnimeList(); };

    http 服务: getUpdAniAnimeList() { return this.httpClient.get<Response<Array<DisplayAnime>>> (${environment.apiUrl}/anime/updAnimeList); }

    路由模块: const routes: Routes = [{ path: '', component: MainComponent, children:[ { path: '', component: HomeComponent, resolve: { data: homeDataFetchGuard }}, ] }, { path: '**', redirectTo: '' } ];

    @NgModule({ imports: [RouterModule.forRoot(routes, { scrollPositionRestoration: 'top' })], exports: [RouterModule] }) export class AppRoutingModule { }

    component:

    constructor(rivate route: ActivatedRoute) { }

    ngOnInit(): void { this.route.data.pipe(map(data => data as Response<Anime>)).subscribe(res => { console.log(res.code); //里面的数据为 undefined });

    }

    大哥们帮忙看看为什么触发这个订阅时 res 内部的数据都为 undefined ,如果代码不够详细我可以提供更多,问题棘手的话我可以付费

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3708 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:40 · PVG 12:40 · LAX 21:40 · JFK 00:40
    ♥ Do have faith in what you're doing.