【发布时间】:2018-03-31 15:29:59
【问题描述】:
我正在尝试在我的 APP_INITIALIZER 中检索 url 中存在的数据
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
...
]
config-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 ./AppBrowserModule@-1:-1
我也尝试在构造函数中使用Injector,但也没有用。
我正在尝试做的事情是否可行?
【问题讨论】:
-
你能在 stackblitz 上创建一个可重现的问题吗?
-
干杯伙伴,这应该是公认的答案
标签: angular