Reputation: 119
These are my 2 files. Home is my default view and i want to show slides first.
Code is as follows:
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");
}
}
Error is:
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)
Upvotes: 2
Views: 2029
Reputation: 898
you have to use navigation as below.
this.navCtrl.push(SlidePage);
Upvotes: 1
Reputation: 6094
slidePage
is not a service to be injected into the component. So you dont have to add it in constructor . Declaring them in app.module.ts
is what you need to do.
slides= SlidePage;
constructor(public qrScan : BarcodeScanner, public navCtrl: NavController) {
if(this.firstLogin){
this.goToSlides();
}
}
goToSlides() {
console.log("show slides >> ");
this.navCtrl.push(this.slides);
};
Dont forget to add the SlidePage
in app.module.ts
declarations
Upvotes: 1