AngularJS - Directives
scope independent communication between directives and controllers
by Shashank Srivastava
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.13/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="appCtrl">
<div enter="loadData()">Roll over to load data</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('appCtrl', function($scope) {
$scope.loadData = function() {
alert('loading data..');
};
});
myApp.directive('enter', function () {
return function (scope, element, attrs) {
element.bind("mouseenter", function() {
scope.$apply(attrs.enter);
});
};
});