将角度2升级到RC5后,我收到如下警告,要求我将组件移动到模块声明:
NgModule AppModule通过“entryComponents”使用AcademylistComponent但是 既没有声明也没有进口!这个警告将成为一个 最后的错误。
我在路由器配置文件中引用了这些组件。看起来像这样:
import {provideRouter,RouterConfig} from '@angular/router';
import {AcademylistComponent} from '../modules/home/component/academyList.component';
import {CourselistComponent} from '../modules/home/component/courseList.component';
import {CreateacademyComponent} from '../modules/home/component/createAcademy.component';
import {ReportsComponent} from '../modules/home/component/reports.component';
import {AuthenticatedGuard} from '../guards/authenticated.guard';
export const routes: RouterConfig = [
{
path: '',
redirectTo:'/home',
terminal:true},
{
path: 'home',
canActivate: [AuthenticatedGuard],
children: [
{path: '', component: AcademylistComponent},
{path: 'my-academies', component: AcademylistComponent},
{path: 'my-courses', component: CourselistComponent},
{path: 'create-academy', component: CreateacademyComponent},
{path: 'reports', component: ReportsComponent}
]
}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
当我将组件移动到ng模块的declarations
数组并将其导入时,路由配置文件确实开始给我Cannot find name
错误。
那么在这种情况下我如何使用模块声明?
答案 0 :(得分:10)
即使您在路线中声明它们,您仍然必须声明NgModule中路线中使用的组件。
@NgModule({
declarations: [
AcademylistComponent,
//.. and so on
],
providers: [
APP_ROUTER_PROVIDERS
]
})
export class AppModule {}