I have a div using *ngFor which loads values from a JSON file. I want to load values from different JSON files randomly each time the div is loaded. Is there a way to achieve this using Math.random() or any other methods?
html file
<div class="row" *ngFor="let data of mydata">
<div class="col">{{data.number}}</div>
<div class="col">{{data.code}}</div>
</div>
ts file
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
@Component({
selector: 'page-showall',
templateUrl: 'showall.html'
})
export class ShowallPage {
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
// providing sample data for development instead of JSON.
datas = [
{
number: "1",
code: "apple",
},
{
number: "2",
code: "orange",
},
{
number: "3",
code: "banana",
},{
number: "50",
code: "lemon",
}
];
mydata = this.datas;
// Using the 'mydata' variable in *ngFor to display values
}