Hello fellow programmer friends,
Need help for the error in the title.
This is my routing module code
app-routing.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {RouterModule,Routes} from '@angular/router';
import { routes } from './routes';
@NgModule({
imports: [
CommonModule,
RouterModule.forRoot(routes)
],
declarations: [RouterModule]
})
export class AppRoutingModule { }
I tried removing RouterModule from the declarations array as well but not getting rectified.
Please help.
答案 0 :(得分:2)
在声明中,您不能添加任何模块。如错误所示:在声明数组中仅允许声明Components,Pipes或Directives
答案 1 :(得分:1)
Understood what mistake I did.
I placed the RouterModule in declarations instead of exports.
This thread may assist future learners who make the same mistake like me.
答案 2 :(得分:1)
将RouterTestingModule
添加到导入数组。
imports: [HttpClientTestingModule, RouterTestingModule]