I would like to load functions dynamically using my ng-repeat. I thought the below code would work but for some reason it is not working. Could someone please help me get the add() and subtract() functions to reference correctly.
Weird this is, when you inspect the HTML, then the functions where inserted correctly, but in the console Angular throws a weird error that I don't understand.
Note: this is just a demo, I need to use this solution at a different place.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p>Click the button to run a function:</p>
<button ng-repeat="x in options" ng-click="{{x.function}}">{{x.text}}</button>
<p>The button has been clicked {{count}} times.</p>
</div>
<script>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.count = 0;
$scope.options = [
{ function: 'add()', text: 'Add'},
{ function: 'subtract()', text: 'Subtract'}
];
$scope.add = function() {
$scope.count++;
};
$scope.subtract = function() {
$scope.count--;
};
}]);
</script>
</body>
</html>