angular - Angular ui中没有路由器提供者
问题描述
I am getting getting a weird error while running the Angular 8 code. Please find the error log shown below:
然而,它抛出错误 Error: $injector:modulerr Module Error
When i load pages nothing happens, where I want it to load the content from the corresponding HTML files.
我正在使用 'angular-route' 进行路由。我可以在我的 require.config 中定义一个 baseurl require.config( baseUrl: '' paths : { 'angular' : '../bower_components/angular/angular.min 吗?
Error: StaticInjectorError(DynamicTestModule)[RouterLinkWithHref -> Router]:
StaticInjectorError(Platform: core)[RouterLinkWithHref -> Router]:
NullInjectorError: No provider for Router!
below is the code snippet :
-------------------------------------------------------------
I am getting getting a weird error while running the Angular 8 code. Please find the error log shown below:
Error: StaticInjectorError(DynamicTestModule)[RouterLinkWithHref -> Router]:
StaticInjectorError(Platform: core)[RouterLinkWithHref -> Router]:
NullInjectorError: No provider for Router!
It is however throwing the error Error: $injector:modulerr Module Error
When i load pages nothing happens, where I want it to load the content from the corresponding HTML files.
我正在使用 'angular-route' 进行路由。我可以在我的 require.config 中定义一个 baseurl require.config( baseUrl: '' paths : { 'angular' : '../bower_components/angular/angular.min 吗?
解决方案
这是失败的,因为您的单元测试文件之一存在问题。这就是错误具有“DynamicTestModule”的原因。请将 RouterTestingModule 添加到您的测试文件中。这是一个示例代码。
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [ MyNewComponentComponent ]
})
.compileComponents();
}));
推荐阅读
- azure - 如何将 asp.net Core 3.1 部署到 Azure
- laravel - 从 laravel 存储播放 m3u8 视频
- java - 以这种方式覆盖 `equals()` 的缺点是什么?
- c++ - C++:函数外的超时函数
- java - 如何解决 java 聚合中的错误输出错误?
- javascript - 将 setInterval 间隔从 100ms 更改为 50ms
- docker - 我的 SaaS 提供商是否使用与其他用户相同的 Docker 映像?
- algorithm - 最小 RGB 路径
- ios - 对具有特定对象的数组进行排序总是在顶部
- android - 如何在 Android 中获取某个位置的方向