将角度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
错误 .
那么在这种情况下如何使用模块声明呢?
1 回答
即使您在路由中声明它们,您仍然必须声明NgModule中路由中使用的组件 .