开发者问题收集

未捕获(承诺中):false NavController ionic2

2017-01-14
2028

这是我的 2 个文件。主页是我的默认视图,我想先显示幻灯片。

代码如下:

home.ts

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

import { NativeStorage ,BarcodeScanner} from 'ionic-native';

import { NavController } from 'ionic-angular';

import { SlidePage } from '../slide/slide';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [BarcodeScanner, SlidePage]
})

export class HomePage {

  firstLogin = true;


  constructor(public qrScan : BarcodeScanner, public slides:SlidePage, public navCtrl: NavController) {
    if(this.firstLogin){
      this.goToSlides();

    }
  }

  goToSlides = function() {
    console.log("show slides >> ");
    this.navCtrl.push(this.slides);
  };


}

slides.ts

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

@Component({
  templateUrl: 'slide.html'
})
export class SlidePage {

  constructor() {
     console.log("dghdghdg");
  }

}

错误是:

dghdghdg
show slides >> 
invalid page component: [object Object]
Error: Uncaught (in promise): false
    at s (polyfills.js:3)
    at polyfills.js:3
    at Object.ti.reject (nav-controller-base.js:187)
    at NavControllerBase._queueTrns (nav-controller-base.js:197)
    at NavControllerBase.push (nav-controller-base.js:52)
    at HomePage.ngOnInit (home.ts:37)
    at Wrapper_HomePage.ngDoCheck (wrapper.ngfactory.js:22)
    at CompiledTemplate.proxyViewClass.View_HomePage_Host0.detectChangesInternal (host.ngfactory.js:37)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381)
2个回答

slidePage 不是要注入到组件中的服务。因此您不必在构造函数中添加它。您需要做的是在 app.module.ts 中声明它们。

  slides= SlidePage;
  constructor(public qrScan : BarcodeScanner, public navCtrl: NavController) {
    if(this.firstLogin){
      this.goToSlides();

    }
  }

  goToSlides() {
    console.log("show slides >> ");
    this.navCtrl.push(this.slides);
  };

不要忘记在 app.module.ts 中添加 SlidePage declarations

raj
2017-01-14

您必须使用如下导航。

this.navCtrl.push(SlidePage);
Atif Hussain
2017-11-29