Exploring AngularJS and attempting to modify an example from a tutorial. I want the ng-init value to be equal to the value passed from a script function. How can I achieve this? Here's the code snippet:
<html>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="mainApp" ng-controller="clickController">
<p>Total click: {{ click.clickCounter() }}</p>
<button ng-click="count = count+1"
ng-init="count=click.clickCounter()">Click Me!</button>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</body>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('clickController', function($scope) {
$scope.click = {
count: 15,
clickCounter: function() {
var foo;
foo = $scope.click;
return foo.count;
}
};
});
</script>
</html>
Currently facing an issue with passing the value of click.clickCounter() to ng-click.