I am new to angular js and still working on things. I would like to ask if it's possible to initiate ng-click variables (which are functions.) in angular js? Here is as snippet of my code
<div data-ng-controller="DeathRayController">
<button data-ng-click="toggleMenu()">Toggle Menu</button>
<ul ng-show="menuState.show">
<li data-ng-repeat="menu in menuList"><a href="" data-ng-click="menu.mode">{{ menu.value }}</a></li>
</ul>
</div>
and here is my controller using angularjs:
var showHide = angular.module('showHide', []);
showHide.controller('DeathRayController', function ($scope) {
// the idea is to display this on the <a ng-click="menu.mode">
$scope.menuList = [
{ mode: 'stun()', value : 'Stun' },
{ mode: 'disinegrate()' ,value : 'Disinegrate' },
{ mode: 'erase()', value : 'Erase' },
];
$scope.menuState = { show: false };
$scope.toggleMenu = function() {
$scope.menuState.show = !$scope.menuState.show;
};
$scope.stun = function() {
alert('Snorlax is stunned!');
};
$scope.disinegrate = function() {
alert('Charizard used Disinegrate!');
};
$scope.erase = function() {
alert('erased Sleep skill');
};
});
If it's still unclear please do tell me.
data-ng-click="menu.mode()", but the mode property should point to a function. In your case i see it as a string variable.