首页 > 解决方案 > 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 吗?

标签: angular

解决方案


这是失败的,因为您的单元测试文件之一存在问题。这就是错误具有“DynamicTestModule”的原因。请将 RouterTestingModule 添加到您的测试文件中。这是一个示例代码。

 beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [RouterTestingModule],
    declarations: [ MyNewComponentComponent ]
  })
  .compileComponents();
}));

推荐阅读