I've been exploring AngularJs and came across an interesting challenge. Here is my custom 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>'
}
})
While this setup works well, I am now curious about achieving the same functionality using bind clicking instead of the ng-click directive. Not necessarily because it's better, but out of sheer curiosity.
I've attempted to implement something like this with no success:
function(scope, element, attrs){
element.bind("click", function(){
scope.$apply(attrs.enter);
})