JSAngular-16
Directives
by munir
HTML
<html ng-app="myApp">
<div ng-controller="Example">
<button click="handler()">{{message}} </button>
</div>
<script>
angular.module('myApp',[])
.directive('click',function(){
return {
restrict: 'A',
link: function($scope,element,attrs){
element.bind('click',function(){
$scope.$eval(attrs.click);
});
}
};
})
.controller('Example',function($scope){
$scope.message = 'Hello!';
$scope.click = function(){
alert($scope.message);
};
});
</script>
</html>