Angular2的最新版本抱怨:NgModule DynamicModule通过"entryComponents"使用HomeComponent. [英] Latest builds from Angular2 complain with: NgModule DynamicModule uses HomeComponent via "entryComponents"
问题描述
自从切换到最新版本的Angular 2(即在github,master上)后,我收到有关所有组件的以下警告:
Since switching to the latest builds of Angular 2 (i.e. on github, master), I get warnings as follows about all my components:
NgModule DynamicModule通过"entryComponents"使用HomeComponent,但是它 既没有宣布,也没有进口!此警告将成为错误 决赛之后.
NgModule DynamicModule uses HomeComponent via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.
除了HomeComponent
,我的所有组件都收到相同的错误消息.
I get the same error message for all my components, in addition to HomeComponent
.
任何人都可以提供有关这些信息吗?
Can anyone please provide information about those?
推荐答案
这也吸引了我. RC5对路由和自举的方式进行了重大更改,并且极大地依赖于app.module.ts
和@NgModule
装饰器.该文档已在此处更新: https://angular.io/docs/ts/latest/和此处的更改日志: https://github.com/angular/angular/blob/master/CHANGELOG.md
This caught me out too. Significant changes in RC5 to the way that you route and bootstrap with a significant reliance on app.module.ts
and @NgModule
decorator. The documentation has been updated here: https://angular.io/docs/ts/latest/ and the changelog here: https://github.com/angular/angular/blob/master/CHANGELOG.md
对路由文件的主要更改是对import
和export
语句的更改.下面显示了一个简单的示例,其中包含两个组成部分AppComponent
和HomeComponent
,它们分别为index.html
中的HomeComponent
:
Main changes to the routing file are changes to the import
and export
statements. A simple example is illustrated below which has two components, AppComponent
and HomeComponent
, that serves HomeComponent
from index.html
:
文件:app.routing.ts
File: app.routing.ts
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';
const appRoutes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'home',
component: HomeComponent
}
];
export const routing = RouterModule.forRoot(appRoutes);`
然后您需要使用NgModule文件:
You then need to use an NgModule file:
文件:app.module.ts
File: app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HomeComponent } from './home.component';
import { routing } from './app.routing';
@NgModule({
imports: [ BrowserModule, routing ],
declarations: [ AppComponent, HomeComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
然后您需要将AppModule
拉到main.ts
并使用它进行引导.
And then you need to pull in AppModule
to main.ts
and bootstrap using it.
文件:main.ts
File: main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);`
此模式不会产生控制台警告消息.
This pattern does not produce the console warning message.
这篇关于Angular2的最新版本抱怨:NgModule DynamicModule通过"entryComponents"使用HomeComponent.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!