这是我的app.module.ts路由代码
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Component } from '@angular/core';
import {RouterModule,Routes, ROUTES} from '@angular/router';
import { AppComponent } from './app.component';
import { from } from 'rxjs';
import {DepartmentListComponent} from './department-list/department-list.component';
import {EmployeeListComponent} from './employee-list/employee-list.component';
const appRoutes: Routes = [
{ path: 'department', component: DepartmentListComponent },
{ path: 'employee', component: EmployeeListComponent },
];
@NgModule({
declarations: [
AppComponent,
RouterModule.forRoot([
{
path: 'new-cmp',
component: EmployeeListComponent
}
])
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
但是我遇到以下错误。
[ts] 类型'ModuleWithProviders'不可分配给'any [] |类型。类型'。 类型“ ModuleWithProviders”不可分配给“类型”。 类型“ ModuleWithProviders”中缺少属性“ apply”。 (属性)Route.component ?:类型
答案 0 :(得分:1)
您需要在导入中导入RouterModule软件包。例如,在下面
进口:[ 浏览器模块,路由器模块 ]