在将角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错误。
那么,在这种情况下,如何使用模块声明呢?
发布于 2016-08-11 17:27:18
即使在路由中声明它们,仍然必须声明NgModule中路由中使用的组件。
@NgModule({
declarations: [
AcademylistComponent,
//.. and so on
],
providers: [
APP_ROUTER_PROVIDERS
]
})
export class AppModule {}https://stackoverflow.com/questions/38894773
复制相似问题