如何访问 route._loadedConfig
成员?它始终未定义。
const a = (route as any)._loadedConfig;
const a = (<any>route )._loadedConfig;
const a = (<any>route )['_loadedConfig'];
这些都不起作用。
VS-Code 在调试窗口中显示值:
最佳答案
假设你想访问 _loadedConfig 的 routes 对象(因为模块对象主要是内部 Angular 东西你不应该真的乱七八糟)我会建议不要直接访问它,因为它不是公共(public) API 的一部分,因此可能会更改或不可靠。
要在加载时访问延迟加载模块的子根,您可以执行如下操作:
创建根注入(inject)服务
@Injectable({
providedIn: 'root'
})
export class LazyLoadedChildRouteService {
public updateLazyLoadedRoutes( childRoutes: Routes ){ ... }
// CONSTRUCTOR
constructor( ... ){ ... }
}
在模块文件中:
export const lazyLoadedRoutes: Routes = [
{
path: 'lazyRoute',
component: LazyLoadedComponent
},
]
@NgModule({
...
imports: [
RouterModule.forChild( lazyLoadedRoutes ),
],
...
})
export class LazyLoadedModule {
/** CONSTRUCTOR */
constructor(
public $translateUrlService: FgTranslateRouterService
) {
this.$translateUrlService.addChildModuleRoutes( lazyLoadedRoutes );
}
}
关于RouteConfigLoadEnd-Handler 中的 Angular 访问 route._loadedConfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53299454/