You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular路由复用策略类注入非同目录服务报错求助

Angular自定义RouteReuseStrategy注入跨目录服务触发NullInjectorError

我参照现有方案实现了自定义DetachedAwareRouteReuseStrategy,并在这个策略类中注入了DetachedComponentTrackingService。编译阶段没有任何错误,但应用运行时抛出以下异常:

main.ts:18 Could not load file 'assets/config/config.dev.json': {"name":"NullInjectorError","ngTempTokenPath":["InjectionToken HTTP_INTERCEPTORS","[object Object]","Router","RouteReuseStrategy","DetachedComponentTrackingService","DetachedComponentTrackingService"]} 

导致页面完全无法加载。奇怪的是,如果注入和路由复用策略类处于同一目录的服务,整个流程就完全正常。想请教下,怎么才能在自定义RouteReuseStrategy中成功注入应用内任意目录的服务?

内容的提问来源于stack exchange,提问作者Mark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 20:24:50