未找到组件工厂 - 导航无法正常工作

时间:2016-12-01 18:03:14

标签: ionic2

使用Ionic v 2.1.12

例外:找不到DetailsPage的组件工厂

按照我能找到的每一条建议都没有运气。对此问题的最新修复建议将页面类添加到声明和entryComponents,但它不起作用。

app.module.ts

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { DetailsPage } from '../pages/details/details';

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

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { DetailsPage } from "../details/details";

@Component({
  selector: 'page-home',
  template: '<button ion-button block (click)="goToDetails()">Search</button>',
})
export class HomePage {

  constructor(private nav: NavController) {  }

  goToDetails() {
    this.nav.push(DetailsPage, {  });
  }

}

details.ts

import { Component } from '@angular/core';

@Component({
  selector: 'details-page',
  template: 'details page',
})
export class DetailsPage {

}

1 个答案:

答案 0 :(得分:0)

我无法复制此问题。 您的代码是正确的。

运行ionic info返回(是的,我的控制台实际上缺少C来自Cordova)

$ ionic info

Your system information:

 ordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v4.5.0
Xcode version: Not installed

最好的办法可能是重新安装离子。

npm uninstall ionic&amp; npm install ionic cordova -g

然后创建一个新项目ionic start newProject blank --v2 --ts。复制并粘贴此问题的代码,运行ionic serve,它应该有效。