Notice: The Monaca & Onsen UI Community Forum is shutting down.
For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.
Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.
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'} ] }]);