Skip to content

Instantly share code, notes, and snippets.

@ejke
Created February 8, 2017 13:37
Show Gist options
  • Save ejke/333e6f1d7f4c7877c3b3d473e12caa73 to your computer and use it in GitHub Desktop.
Save ejke/333e6f1d7f4c7877c3b3d473e12caa73 to your computer and use it in GitHub Desktop.
Ionic2 dynamically change links with ngFor
<ion-grid>
<ion-row>
<ion-col width-33 *ngFor="let info of infos">
<div class="instructions" [navPush]="info.tap">
<div>
<img src="assets/icons/{{info.icon}}.png" alt="Icon">
</div>
<span>{{info.title}}</span>
</div>
</ion-col>
</ion-row>
</ion-grid>
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { NumbersPage } from '../hadaabinumbrid/hadaabinumbrid';
import { StatePage } from '../maakond/maakond';
import { AboutPage } from '../naiskodukaitse/naiskodukaitse';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
infos: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.infos = [
//first two are strings, last one object, that directs on click with navPush directly to necessary page
{title: 'Contact numbers', icon: 'numbers', tap: NumbersPage},
{title: 'States represented', icon: 'states', tap: StatePage},
{title: 'About us', icon: 'us', tap: AboutPage}
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment