I have an array of object which I use ng-repeat to iterate over. However, every object has 2 properties - a country (string) and cities (array). How can I randomize this array of cities on some button click or page refresh. An example:
$scope.package = [{
country: 'Sweden',
cities: ['aaa', 'bbb']
}, {
country: 'Sudan',
cities: ['yyy', 'zzz']
}]
$scope.showNext = function() {
// shows next slide but randomize the cities
}
<ul>
<li ng-repeat="pack in package">
<p></p>
<span></span> <!-- cities should be random value from the array -->
</li>
</ul>
<button ng-click="showNext()"> Next Country </button>
NOTE: It's not required that the button do the randomizing. The button just jumps to next country slide but that the cities name should be shuffled every time.
Aucun commentaire:
Enregistrer un commentaire