'router-outlet' is not a known element

后端 未结 12 1348
无人及你
无人及你 2021-01-30 19:36

I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I ad

12条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 19:59

    If you are doing unit testing and get this error then Import RouterTestingModule into your app.component.spec.ts or inside your featured components' spec.ts:

    import { RouterTestingModule } from '@angular/router/testing';
    

    Add RouterTestingModule into your imports: [] like

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

提交回复
热议问题