簡體   English   中英

Ionic2未捕獲的承諾

[英]Ionic2 uncaught promise

我目前正在學習Ionic2中圍繞Angular2的繩索。 我正在閱讀一個過時的教程,由於我不是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

這些是我從全新ionic2安裝中更改的文件:

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

 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 {} 

我還通過ionic g page命令創建了3頁。

在這個問題上的任何幫助將不勝感激。

您需要包括ReposPagengModuleapp.module.ts。 它應該同時存在於聲明和entryComponents數組中。

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

正如錯誤消息明確指出的那樣,您需要將'ReposPage'添加到app.modules.ts文件中的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