本文介绍了无法实例化循环依赖! ApplicationRef("[ERROR->]"):在./AppModule@-1:-1中的NgModule AppModule中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    providers: [ AppConfigService,
            {
                provide: APP_INITIALIZER,
                useFactory: (config: AppConfigService) => () => config.getAppConfig(),
                deps: [AppConfigService],
                multi: true
            },
]

遇到此错误

问题:我使用了 ngx-permission pkg获得许可.我设置了 route 权限方法.但是,当我刷新页面时,该时间会重定向到首页,而不是停留在当前页面上.所以我尝试在应用程序启动之前加载权限解决方法,但出现此错误.

Issue: i have used ngx-permission pkg for permission. i set route permission method. but when i refresh a page that time redirect on home page instead stay on current page. so i tried to load permissions before application start up method for resolve this issue but got this error.

 config.getAppConfig() // call when application start up

有任何想法请帮助.其他解决方案也欢迎.

have any idea please help. other solution also welcome.

推荐答案

我已经解决了该解决方案的问题

i had fixed my issue with this solution

在app.module.ts中创建函数

create function into app.module.ts

export function loadConfig(appService: AppConfigService): Function {
    return () => appService.getAppConfig();
}

 AppConfigService,
        {
            provide: APP_INITIALIZER,
            useFactory: loadConfig,
            deps: [AppConfigService],
            multi: true
        },

issue into `HttpInterceptor` so i used injector for that
constructor(private inj: Injector) {
        super(
            inj.get(XHRBackend),
            inj.get(RequestOptions)
        );
}

这篇关于无法实例化循环依赖! ApplicationRef("[ERROR->]"):在./AppModule@-1:-1中的NgModule AppModule中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 20:51