• [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).

  • 相关阅读:
    来换网心得总结
    关于项目来换网
    数据库设计源代码
    自我介绍
    WC项目
    关于《现代软件工程》此书的疑问
    Swift基础语法(常量变量、数据类型、元组、可选、断言等)
    grunt快速学习
    Swift语言简介
    Swift简单入门教程:30分钟玩转Swift
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4173057.html
Copyright © 2020-2023  润新知