这些是我的2个文件。 Home是我的默认视图,我想先显示幻灯片。
代码如下:
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)
答案 0 :(得分:1)
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);
};
别忘了在SlidePage
app.module.ts
declarations
答案 1 :(得分:1)
你必须使用如下导航。
this.navCtrl.push(SlidePage);