这是我的 2 个文件。主页是我的默认视图,我想先显示幻灯片。
代码如下:
首页
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);
};
}
幻灯片.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)
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
declarations
中添加SlidePage
您必须按如下方式使用导航。
this.navCtrl.push(SlidePage);