2017-05-06 6 views
27

の違いは何ですか:私はapp.module.tsでこれを持って宣言とentryComponents

import { BrowserModule } from '@angular/platform-browser'; 
import { ErrorHandler, NgModule } from '@angular/core'; 
import { HttpModule, Http } from '@angular/http'; 
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; 
import { EliteApi } from '../shared/shared'; 
import { MyApp } from './app.component'; 
import { MyTeams, Tournaments, TeamDetails, Teams, TeamHome, Standings } from '../pages/pages'; 

import { StatusBar } from '@ionic-native/status-bar'; 
import { SplashScreen } from '@ionic-native/splash-screen'; 

@NgModule({ 
    declarations: [ 
     MyApp, 
     MyTeams, 
     TeamDetails, 
     Tournaments, 
     Teams, 
     TeamHome, 
     Standings 
    ], 
    imports: [ 
     BrowserModule, 
     IonicModule.forRoot(MyApp), 
     HttpModule 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
     MyApp, 
     MyTeams, 
     TeamDetails, 
     Tournaments, 
     Teams, 
     TeamHome, 
     Standings 
    ], 
    providers: [ 
     HttpModule, 
     StatusBar, 
     SplashScreen, 
     { provide: ErrorHandler, useClass: IonicErrorHandler },   
     EliteApi 
    ] 
}) 
export class AppModule { } 

は、現時点では私のdeclarationsentryComponents両方がまったく同じです。彼らは私のアプリケーション用に構築したすべてのページ/コンポーネントを含んでいます。いずれかのプロパティからエントリを削除すると、angular2でエラーが発生します。

私の質問は、いつも同じであれば、これらのプロパティの必要性は何ですか?私は間違いなくここにいくつかの点を欠いていると思う。 entryComponentsとdeclaractionsはいつ異なるでしょうか?

答えて

57

entryComponentsアレイは、HTMLに存在し、ComponentFactoryResolverと動的に作成されていないだけコンポーネントを定義するために使用されます。 Angularは、このヒントを見つけてコンパイルする必要があります。他のすべてのコンポーネントは宣言配列にリストされるべきです。ここで

はドキュメントです:

https://angular.io/docs/ts/latest/cookbook/ngmodule-faq.html#!#q-entry-component-defined

+0

[OK]を、私は見てます –

関連する問題