Reputation: 77
Here I'm developing moving from one page to another page in IONIC
. So that I developed below code
<div *ngFor="let list of product">
<img [src] ='list.imge'/>
<button ion-button round (click)="Contact()">view</button>
</div>
and typescript
is
export class HomePage {
product:any[]=[{id:121,name:"iphone",imge:'assets/img/iphone.png'}]
constructor(public navCtrl: NavController) {
}
Contact() {
this.navCtrl.push('ContactPage');
}
}
core.js:1449 ERROR Error: Uncaught (in promise): invalid link: ContactPage at c (polyfills.js:3)
Once I click on view button it is not moving to another page.
Edit contactpage type script
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-contact',
templateUrl: 'contact.html'
})
export class ContactPage {
constructor(public navCtrl: NavController) {
}
}
Upvotes: 1
Views: 1152
Reputation: 3391
in case it's lazy loaded:
import { NavController } from 'ionic-angular';
// IMPORT ContactPage IF NOT LAZY-LOADED
import { ContactPage} from path;
export class HomePage {
constructor(private navCtrl:NavController){}
// IF LAZY-LOADED
Contact(){
this.navCtrl.push('ContactPage');
}
// IF NOT LAZY-LOADED
Contact(){
this.navCtrl.push(ContactPage);
}
}
Upvotes: 1
Reputation: 185
Your HTML
<div *ngFor="let list of product">
<img [src] ='list.imge'/>
<button ion-button round (click)="Contact()">view</button>
</div>
Modify your Typescript like this
import { ContactPage} from '../../pages/contact/contact';
.......
export class HomePage {
product:any[]=[{id:121,name:"iphone",imge:'assets/img/iphone.png'}]
constructor(public navCtrl: NavController) {
}
Contact() {
this.navCtrl.push(ContactPage);
OR
this.navCtrl.setRoot(ContactPage);//(if you want block backbutton)
}
}
Upvotes: 0
Reputation: 1146
Your ContactPage should contain module. Is that created using ionic page generate command?
Reference link:
https://ionicframework.com/docs/cli/generate/
You can push a page for navigation using two ways.
1) Import page in page does not contain a module. And navigate like :
import { ContactPage } from path;
this.navCtrl.push(ContactPage);
2) If a page has a module, navigate like:
this.navCtrl.push('ContactPage');
Upvotes: 0