I’m still trying to understand the angular2 module concept. I’m playing with the tabs
starter and tried to make all the /pages
a separate PagesModule
module.
src/pages/pages.module.ts
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AgmCoreModule } from 'angular2-google-maps/core/core-module';
import { IonicModule } from 'ionic-angular';
import { MyApp } from '../app/app.component';
import { AboutPage } from './about/about';
import { ContactPage } from './contact/contact';
import { HomePage } from './home/home';
import { TabsPage } from './tabs/tabs';
@NgModule({
imports: [
CommonModule, // for ng2 directives
IonicModule.forRoot(TabsPage), // root for PagesModule
],
declarations: [
AboutPage,
ContactPage,
HomePage,
TabsPage
],
exports: [
AboutPage,
ContactPage,
HomePage,
TabsPage
],
providers: []
})
export class PagesModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: PagesModule,
providers: [ ]
};
}
}
But I need to use TabsPage
as the root in the AppModule
and Typescript but I’m getting various "No Component Factory Found..."
errors.
app/app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
// import { TabsPage } from '../pages/tabs/tabs';
import { PagesModule } from '../pages/pages.module';
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
rootPage = TabsPage; // this is exported from the PagesModule, but it's not found here
constructor(platform: Platform) {
platform.ready().then(() => {
});
}
}
app/app.module.ts
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
// import { AboutPage } from '../pages/about/about';
// import { ContactPage } from '../pages/contact/contact';
// import { HomePage } from '../pages/home/home';
// import { TabsPage } from '../pages/tabs/tabs';
import { PagesModule } from '../pages/pages.module';
@NgModule({
declarations: [
MyApp,
// AboutPage,
// ContactPage,
// HomePage,
// TabsPage // how do I declare TabsPage from the PagesModule here?
],
imports: [
IonicModule.forRoot(MyApp),
PagesModule.forRoot(),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
// AboutPage,
// ContactPage,
// HomePage,
// TabsPage
],
providers: []
})
export class AppModule {}
How do I declare TabsPage
from the PagesModule
here in the AppModule
so I can use it in MyApp
? Or is the answer that MyApp
must belong to the PagesModule
?