AngularJS Dynamic ng-click function assignment
AngularJS Dynamic ng-click function assignment
HTML
<!-- template1.html -->
<script type="text/ng-template" id="template1.html">
Content of template1.html asdfadsf
</script>
<!-- template2.html -->
<script type="text/ng-template" id="template2.html">
Content of template2.html
</script>
<div ng-controller="Ctrl">
<select ng-model="selectedFunction" ng-options="funcName for ( funcName , function ) in functionCollection"></select>
<button ng-click="selectedFunction()">Execute Function</button>
</div>
JavaScript
function Ctrl($scope) {
$scope.functionCollection =
{ howdy: function(){alert('howdy');},
hello: function(){alert('hello');}
};
$scope.selectedFunction = function(){alert('no function selected!');};
}