我试图找回出现在URL数据在我APP_INITIALIZER角4与注射途径
app.module.ts
export function init(config: ConfigService, router: Router) {
return() => config.load(router);
}
providers : [
...
{
provide: APP_INITIALIZER,
useFactory: init,
deps: [ConfigService, Router],
multi: true
},
ConfigService
...
]
配置,service.ts
@Injectable()
export class ConfigService
load(router: Router): Promise<any> {
console.log('current url : ' + router.url);
return new Promise(((resolve, reject) => resolve()));
}
}
不幸的是我收到
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppBrowserModule in ./[email protected]:-1
我也尝试在构造函数中使用Injector
,但它也不起作用。
我试图做甚至可行吗?
你可以在stackblitz上创建一个可重现的问题吗? –
干杯队友,应该是公认的答案 – Scipion