angular - declarations 和 entryComponents 有什么区别

标签 angular

我的 app.module.ts 中有这个:

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 和 declarations 何时会彼此不同?

最佳答案

entryComponents 数组用于定义 在 html 中找不到并使用 ComponentFactoryResolver 动态创建的组件。 Angular 需要这个提示来找到它们并编译。所有其他组件应仅列在声明数组中。

Here's the documentation on angular site

关于angular - declarations 和 entryComponents 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43815995/

相关文章:

angular - 在 Angular 5 应用程序中找不到 Devextreme-intl 本地化消息

javascript - 如何为 [ngStyle] 设置动态 css 样式

angular - 默认情况下使用 http 运行时如何使用 https 运行 Angular?

Angular - 删除后刷新/获取数据

angular - 如何在与我的 http 服务器不同的端口上提供 Angular 应用程序

Angular 模板 : Disable div in production mode

angular - 加速 Angular Material 自动完成或替代方案

html - 当我们知道 key 时如何显示 map 的内容

angular - 如何从 nrwl 工作区 libs 文件夹延迟加载模块?

javascript - @storybook/angular 无法在故事索引上加载 scss 文件