AngularJS bind clicking instead of ng-click

angularjs, javascript

Solution

Try this one:

myApp.directive("enter", function(){
  return{
    restrict: 'A',
    scope:{},
    controller: function($scope){
        $scope.logSomething=function(somevalue){
            console.log(somevalue+" is logged");
        }
    },
    template: '<input type="text" ng-model="myModel">'+
              '<div button>click me</div>'
}
});

myApp.directive("button", function(){   
  return{
    restrict: 'A',
    link: function(scope , element){
       element.bind("click", function(e){
          scope.logSomething( scope.myModel );
       });
    }
}
});

Plunk: http://plnkr.co/edit/RCcrs5?p=preview

Problem

I was looking at AngularJs and have a question, this is my directive: ``` myApp.directive("enter", function(){ return{ restrict: 'A', scope:{}, controller: function($scope){ $scope.logSomething=function(somevalue){ console.log(somevalue+" is logged"); } }, template: '<input type="text" ng-model="myModel">'+ '<div ng-click="logSomething(myModel)">click me</div>' } }) ``` This works, but my question is how can I do the same thing using bind clicking instead of ng-click directive? Not that it is better(maybe?), but for curiosity it should be including something like this but couldn't get the big picture: ``` function(scope, element, attrs){ element.bind("click", function(){ scope.$apply(attrs.enter); }) ```

Original source