Using Angular, I'm trying to pass a local variable from constructor the into the HTML.
Here is my TS:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-random',
templateUrl: 'random.html'
})
export class RandomPage {
constructor(public navCtrl: NavController) {
var restaurants = [
'Restaurant1',
'Restaurant2',
'Restaurant3'
];
var restaurant = restaurants[Math.floor(Math.random()*restaurants.length)];
console.log(restaurant);
}
}
Here is my HTML:
<ion-content padding>
<ion-item>
{{restaurant}}
</ion-item>
</ion-content>
restaurant is being logged when the constructor fires. I'm just not sure how to display it in the HTML. What am I missing?
this.restaurant = ...instead ofvar restaurantwork? you want the value to be a property of the controller, not just a random variable...