Create policies with Angularjs

1

The button should display an alert but nothing appears, nor an error. What is wrong? Here is the code:

  angular.module('App', [])
                    .directive('sonclick', function () {    
                         return {
                             restrict: 'A',
                             link: function(scope,element,attrs){
                                 element.bind('click',function(){       
                                     scope.$eval(attrs.sonclick);
                                 })
                             }
                         };
                    })
                    .controller('CtrlApp', function ($scope) {
                          $scope.executa = function(){
                              alert("scope");           
                          };
                    });
<!DOCTYPE HTML>
<html ng-app="App">
    <head>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"type="text/javascript"></script>
    </head>
    <body>
        <div ng-controller="CtrlApp">
            <button son-click="executa()">clique aqui</button>

        </div>  
       
    </body>
</html>
    
asked by anonymous 12.01.2015 / 20:35

1 answer

3

Changing sonclick by sonClick (attention to uppercase C) seems to solve the problem.

  angular.module('App', [])
                    .directive('sonClick', function () {    
                         return {
                             restrict: 'A',
                             link: function(scope,element,attrs){
                                 element.bind('click',function(){       
                                     scope.$eval(attrs.sonClick);
                                 })
                             }
                         };
                    })
                    .controller('CtrlApp', function ($scope) {
                          $scope.executa = function(){
                              alert("scope");           
                          };
                    });
<!DOCTYPE HTML>
<html ng-app="App">
    <head>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"type="text/javascript"></script>
    </head>
    <body>
        <div ng-controller="CtrlApp">
            <button son-click="executa()">clique aqui</button>

        </div>  
       
    </body>
</html>
    
12.01.2015 / 21:06