Anmol Nijhawan Anmol Nijhawan - 23 days ago 10
AngularJS Question

Event using ng-click is not working?


I am new to angularjs in this angular code i want to increase the
value of the fib variable. For this i made a function named as fibapp
. here i have the html and angular code below please help to run it.


ang.js

`

var mod=angular.module("myModule",[]);
mod.controller("events",function($scope)
{
fib=0;
$scope.fib=fib;
$scope.fibapp=function(fib)
{
fib++;
}
}
);


`

HTML code using the Above angular code

`

<html>
<head>
<script src="E:/angular.min.js"></script>
<script src="E:/ang.js"></script>
</head>
<body ng-app="myModule">
<div ng-controller="events">
<p>{{fib}}</p>
<input type="button" ng-click="fibapp(fib)">
</div>
</body>
</html>


`

Answer

Use this:

var mod=angular.module("myModule",[]);
mod.controller("events",function($scope)
{
   fib=0;
   $scope.fib=fib;
   $scope.fibapp=function(fib)
   {
      $scope.fib++;
   }
}

Here is a jsfiddle

Comments