Filter - Directives
directive to directive communication
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.13/angular.min.js"></script>
<div ng-app="superApp">
<superhero strength>The Hulk</superhero>
</div>
JavaScript
var myApp = angular.module('superApp', []);
myApp.directive('superhero', function() {
return {
restrict: 'E',
controller: function($scope) {
$scope.abilities = [];
this.addStrength = function() {
$scope.abilities.push("Strength");
};
this.addFlight = function() {
$scope.abilities.push("Flight");
};
},
link: function(scope, element) {
element.bind("mouseenter", function() {
alert(scope.abilities);
})
}
};
});
myApp.directive('strength', function() {
return {
require: "superhero",
link: function(scope, element, attrs, superheroCtrl) {
superheroCtrl.addStrength();
}
};
});
myApp.directive('flight', function() {
return {
require: "superhero",
link: function(scope, element, attrs, superheroCtrl) {
superheroCtrl.addFlight();
}
};
});