angularjs - Is it possible to know which directive initialized my controller -
let's have 2 directives:
angular.module('example').directive('dir1', function () { return { restrict: 'a', scope: true, controller: 'examplectrl' };}); angular.module('example').directive('dir2', function () { return { restrict: 'a', scope: true, controller: 'examplectrl' };}); is possible tell directive initialized examplectrl inside controller?
you can this:
angular.module('example').directive('dir1', function () { return { restrict: 'a', scope: true, controller: 'examplectrl', controlleras: 'dir1ctrl' };}); angular.module('example').directive('dir2', function () { return { restrict: 'a', scope: true, controller: 'examplectrl', controlleras: 'dir2ctrl' };}); then, in controller, $scope.dirncontroller, n 1 or 2 or many have, exist if came directive n. how controlleras syntax works, published scope.
something this:
app.controller('examplectrl', function($scope, $element) { if ($scope.dir1ctrl) /* */ if ($scope.dir2ctrl) /* else */ });
Comments
Post a Comment