首页 > 代码库 > [AngularJS] Directive using another directive by 'require'
[AngularJS] Directive using another directive by 'require'
Directive can use another directive though ‘require‘ keyword.
angular.module(‘docsTabsExample‘, []).directive(‘myTabs‘, function() { return { restrict: ‘E‘, transclude: true, scope: {}, controller: function($scope) { var panes = $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 has a require
option with value ^myTabs
. When a directive uses this option, $compile
will throw an error unless the specified controller is found. The ^
prefix means that this directive searches for the controller on its parents (without the ^
prefix, the directive would look for the controller on just its own element).
[AngularJS] Directive using another directive by 'require'
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。