angularjs a directive example

The a directive of angularjs is modifed form the html A tag so that the default action is prevented when the href attribute is empty.
You can refer direct AngularJs doc for this to know more. In this post i just want to make a example to help you learn easy.




 <html>  
 <head>  
   <title>Angular JS Directive</title>  
   <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>  
   <script>  
     angular.module('MyForm', [])  
       .controller('myController', ['$scope', function ($scope) {  
         $scope.count = 0;  
         $scope.list = [];  
         $scope.Addone = function () {  
           $scope.count++;  
           $scope.list.push("Add item " + $scope.count.toString());  
         };  
       }]);  
   </script>  
 </head>  
 <body ng-app="MyForm">  
   <div ng-controller="myController">  
     <h1>a directive and ng-click example</h1>  
     <a href="" ng-click="Addone()">Add Item</a>  
     <ul>  
       <li ng-repeat="l in list">  
         {{l}}  
       </li>  
     </ul>  
   </div>  
 </body>  
 </html>   

Please focus a highlight code and run it you will know.

Thanks for your time reading


No comments:

Post a Comment

Popular Posts