Directive can use another Directive though ' require ' keyword.
Angular.module (' Docstabsexample ', []). Directive (' Mytabs ',function() { return{restrict:E, transclude:true, scope: {}, Controller:function($scope) {varpanes = $scope. Panes = []; $scope. Select=function(Pane) {Angular.foreach (panes,function(pane) {pane.selected=false; }); Pane.selected=true; }; This. AddPane =function(pane) {if(Panes.length = = 0) {$scope. Select (pane); } panes.push (pane); }; }, Templateurl:' My-tabs.html ' };}). Directive (' Mypane ',function() { return{ require:' ^mytabs ', restrict:E, transclude:true, scope: {title:‘@‘}, Link:function(scope, element, Attrs, Tabsctrl) {Tabsctrl.addpane (scope); }, Templateurl:' My-pane.html ' };});
The myPane
directive have a require
option with value ^myTabs
. When a directive uses this option, would $compile
throw a error unless the specified controller is found. ^
The prefix means that this directive searches for the controller in its parents (without ^
the prefix, the Direc Tive would look for the controller on just it own element).
[AngularJS] Directive using another Directive by ' require '