O'Reilly logo

Mastering AngularJS for .NET Developers by Mohammad Wadood Majid, Golrokh Mirzaei

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Directive-to-directive communication

In order to communicate with other directives, we need the controller function of a directive. In some cases, we need to combine two directives to create a particular HTML component. The following code example shows how different directives communicate with each other:

var app = angular.module('myApp', []); app.directive("cars", function () { return { restrict: 'AEC', controller: function ($scope, $element, $attrs) { $scope.carTypes = []; this.ford = function () { $scope.carTypes.push('Ford'); }; this.chrysler = function () { $scope.carTypes.push('Chrysler') }; }, link: function (scope, element) { element.bind('click', function () { '<div>scope.content</div>'; }); } }; }); app.directive('ford', function () { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required