How to make button to pushing a page using a value of an array inside ng-click?
-
I was trying to create a few buttons using an array in Angularjs.
My question is how to put a value like function or code like myNavigator.pushPage(‘page’) inside ng-click from an array and make the button work to navigatingThis is my code
HTML
<template id="home"> <ons-page> <ons-toolbar> <div class="left"> <ons-back-button></ons-back-button> </div> <div class="center">Home</div> </ons-toolbar> <ons-list ng-repeat="x in data"> <ons-list-item ng-click="x.link"> {{x.btn}} </ons-list-item> </ons-list> </ons-page> </template>
AngularJS
var module = angular.module('app', ['onsen']); module.controller('Ctrl', ['$scope', function ($scope){ $scope.pg1 = function(){ myNav.pushPage('pg1'); }; $scope.pg2 = function(){ myNav.pushPage('pg2'); }; $scope.pg3 = function(){ myNav.pushPage('pg3'); }; $scope.tombol = [ {link:'pg1()', data:'Tombol 1'}, {link:'pg2()', data: 'Tombol 2'}, {link:'pg3()', data: 'Tombol 3'} ] }]);