What is entryComponents in angular ngModule?

By : raj
Source: Stackoverflow.com
Question!

I am working on an Ionic app ( 2.0.0-rc0 ) which depends on angular 2 . So the new introduction of ngModules is included. I am adding my app.module.ts. below.

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { Users } from '../pages/users/users';

@NgModule({
  declarations: [
    MyApp,
    Users
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    Users
  ],
  providers: []
})
export class AppModule {}

What does entryComponents do here? Components are already defined in declarations . So what the need of repeating them ? I am fairly new to angular and ionic.

By : raj


Answers

This is for dynamically added components that are added using ViewContainerRef.createComponent(). Adding them to entryComponents tells the offline template compiler to compile them and create factories for them.

The components registered in route configurations are added automatically to entryComponents as well because router-outlet also uses ViewContainerRef.createComponent() to add routed components to the DOM.

https://angular.io/docs/ts/latest/api/core/index/NgModule-interface.html#!#entryComponents-anchor

Defines the components that should be compiled as well when this component is defined. For each components listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.



name = q.Attribute("type").Value;


This video can help you solving your question :)
By: admin