简体   繁体   English

Ionic2未捕获的承诺

[英]Ionic2 uncaught promise

I am currently learning the ropes around Angular2 in Ionic2. 我目前正在学习Ionic2中围绕Angular2的绳索。 I am going through a tutorial that is a bit outdated, and since i'm not 100% familiar with Angular2 environments, I can't debug this error: 我正在阅读一个过时的教程,由于我不是100%熟悉Angular2环境,所以无法调试此错误:

Uncaught (in promise): Error: No component factory found for ReposPage. Did you add it to @NgModule.entryComponents? Error: No component factory found for ReposPage. Did you add it to @NgModule.entryComponents? at noComponentFactoryError

These are the files I've changed from a clean ionic2 install: 这些是我从全新ionic2安装中更改的文件:

app.component.ts app.component.ts

 import { Component, ViewChild } from '@angular/core'; import { Platform, MenuController, Nav } from 'ionic-angular'; import { HelloIonicPage } from '../pages/hello-ionic/hello-ionic'; import { ListPage } from '../pages/list/list'; import { UsersPage } from '../pages/users/users'; import { ReposPage } from '../pages/repos/repos'; import { OrganisationsPage } from '../pages/organisations/organisations'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; @Component({ templateUrl: 'app.html' }) export class MyApp { @ViewChild(Nav) nav: Nav; // make HelloIonicPage the root (or first) page rootPage = HelloIonicPage; pages: Array<{title: string, component: any}>; constructor( public platform: Platform, public menu: MenuController, public statusBar: StatusBar, public splashScreen: SplashScreen ) { this.initializeApp(); // set our app's pages this.pages = [ { title: 'Users', component: UsersPage }, { title: 'Repos', component: ReposPage }, { title: 'Organisations', component: OrganisationsPage }, { title: 'Hello Ionic', component: HelloIonicPage }, { title: 'My First List', component: ListPage } ]; } initializeApp() { this.platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. this.statusBar.styleDefault(); this.splashScreen.hide(); }); } openPage(page) { // close the menu when clicking a link from the menu this.menu.close(); // navigate to the new page if it is not the current page this.nav.setRoot(page.component); } } 

app.module.ts app.module.ts

 import { BrowserModule } from '@angular/platform-browser'; import { NgModule, ErrorHandler } from '@angular/core'; import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; import { MyApp } from './app.component'; import { HelloIonicPage } from '../pages/hello-ionic/hello-ionic'; import { ItemDetailsPage } from '../pages/item-details/item-details'; import { ListPage } from '../pages/list/list'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; @NgModule({ declarations: [ MyApp, HelloIonicPage, ItemDetailsPage, ListPage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), ], bootstrap: [IonicApp], entryComponents: [ MyApp, HelloIonicPage, ItemDetailsPage, ListPage ], providers: [ StatusBar, SplashScreen, {provide: ErrorHandler, useClass: IonicErrorHandler} ] }) export class AppModule {} 

I have also created 3 pages through the ionic g page command. 我还通过ionic g page命令创建了3页。

any help on this issue would be grateful. 在这个问题上的任何帮助将不胜感激。

You need to include ReposPage in ngModule in app.module.ts . 您需要包括ReposPagengModuleapp.module.ts。 It should be present in both declarations and entryComponents array. 它应该同时存在于声明和entryComponents数组中。

@NgModule({
  declarations: [
    MyApp,
    HelloIonicPage,
    ItemDetailsPage,
    ListPage,
    ReposPage //here
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HelloIonicPage,
    ItemDetailsPage,
    ListPage,
    ReposPage //here
  ],

as the error message clearly saying, you need to add 'ReposPage' to the entryComponents array in app.modules.ts file. 正如错误消息明确指出的那样,您需要将'ReposPage'添加到app.modules.ts文件中的entryComponents数组中。 Also you would need to add it as a declaration. 另外,您需要将其添加为声明。

declarations: [ MyApp, HelloIonicPage, ItemDetailsPage, ListPage, ReposPage ] 声明:[MyApp,HelloIonicPage,ItemDetailsPage,ListPage,ReposPage]

entryComponents: [ MyApp, HelloIonicPage, ItemDetailsPage, ListPage, ReposPage ] entryComponents:[MyApp,HelloIonicPage,ItemDetailsPage,ListPage,ReposPage]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM