angular - RC5 NgModules 声明

标签 angular typescript

将 Angular 2 升级到 RC5 后,我收到如下警告,要求我将组件移至模块声明:

NgModule AppModule uses AcademylistComponent via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.

我在我的路由器配置文件中引用了这些组件。看起来像这样:

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 数组并将它们导入到那里时,路由配置文件确实开始给我找不到名称错误。

那么在这种情况下我该如何使用模块声明呢?

最佳答案

即使您在路由中声明它们,您仍然必须在 NgModule 中声明路由中使用的组件。

@NgModule({
  declarations: [
    AcademylistComponent,
    //.. and so on
  ], 
  providers: [
    APP_ROUTER_PROVIDERS
  ]
})
export class AppModule {}

关于angular - RC5 NgModules 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38894773/

相关文章:

reactjs - 在 React 中使用 Firebase 9、Redux Toolkit 和 Typescript 令人头疼。 'dispatch' 不知何故具有类型 'never' ?

typescript - 我的 Stripe 签名 key 是什么,我在哪里可以找到它?

typescript - WebStorm:参数类型不可分配给参数类型 ObjectConstructor

javascript - index.js 没有做 index.ts 做的事情

angular - 在 Angular Material 中获取输入按键事件的值

javascript - Angular 2 在 View /模板中调用函数

Angular 2 - 5 动画但没有 *ngIf

angularjs - 为 Angular 2 实现 ngClassEven ngClassOdd

angular - 提交具有条件的两个不同 Api 的表单

angular - 从 Angular Material 选择中删除焦点下划线边框