我正在尝试将Angular的APP_INITIALIZER
集成到我的项目中,以便在启动应用程序之前执行一些功能。当我在服务中使用Angular中的 ActivatedRoute 时,就会出现问题。
错误是:
Error: Provider parse errors:
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
我想我内部使用了两次import或类似的东西。基本上,我尝试了其他一些配置,但最后总是抛出相同的错误。
STACKBLITZ示例: https://stackblitz.com/edit/angular-bhpe7m
预期的行为:只是为了能够通过ActivatedRoute服务检索一些QueryParam,并在运行Angular应用之前对其进行一些功能
答案 0 :(得分:10)
确保在您的app.module.ts中包含HttpClientModule
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule
],
})
export class AppModule { }
答案 1 :(得分:1)
遇到了问题,只需从“ appLoaderService”中删除路由器
$ bazel build --copt="-DUSE_GEMM_FOR_CONV" tensorflow/python/tools:print_selective_registration_header
...
INFO: Analyzed target //tensorflow/python/tools:print_selective_registration_header (377 packages loaded, 24256 targets configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base /private/var/tmp/_bazel_glebdavydov/01d4cf1f69cd2606674d307a7a455e95/sandbox
ERROR: /Users/glebdavydov/Downloads/tensorflow-master/tensorflow/c/BUILD:372:1: undeclared inclusion(s) in rule '//tensorflow/c:ops':
this rule is missing dependency declarations for the following files included by 'tensorflow/c/ops.cc':
'tensorflow/contrib/makefile/downloads/absl/absl/strings/string_view.h'
'tensorflow/contrib/makefile/downloads/absl/absl/types/optional.h'
Target //tensorflow/python/tools:print_selective_registration_header failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 54.737s, Critical Path: 13.10s
INFO: 4 processes: 4 local.
FAILED: Build did NOT complete successfully
由于要在初始化应用程序的配置中注入路由,因此您获得了循环依赖性。
由于您一直未使用它,因此请删除它。
但是,如果在加载自举组件之前缩进使用route,则可以寻求解析器或保护。
如上所述,虽然有办法**,但无法在APP_INITIALIZER内部使用路由,但我最好建议如下使用Resolver:
constructor(private route: ActivatedRoute) {} // remove this dependency
Resolver供参考
编辑 将代码放入解析器后,您将得到以下内容:
答案 2 :(得分:-3)
我通过使用以下代码更新软件包来解决了这个问题。
ng add @angular/localize