Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJs-在UI引导上添加自定义类';s标签_Javascript_Angularjs_Angular Ui Bootstrap_Bootstrap Tabs - Fatal编程技术网

Javascript AngularJs-在UI引导上添加自定义类';s标签

Javascript AngularJs-在UI引导上添加自定义类';s标签,javascript,angularjs,angular-ui-bootstrap,bootstrap-tabs,Javascript,Angularjs,Angular Ui Bootstrap,Bootstrap Tabs,如何在UI Bootsrap的选项卡Nav上替换或添加新类。我期待着这样的事情 <ul class="MY-CUSTOM-CLASS" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" ng-transclude=""> <li ng-class="{active: active, disabled: disabled}" heading="Justified" class="ng-i

如何在UI Bootsrap的选项卡Nav上替换或添加新类。我期待着这样的事情

<ul class="MY-CUSTOM-CLASS" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" ng-transclude="">
       <li ng-class="{active: active, disabled: disabled}" heading="Justified" class="ng-isolate-scope">
            <a href="" ng-click="select()" tab-heading-transclude="" class="ng-binding">Justified</a>
       </li>

       .....          
</ul> 
  • .....
我尝试了以下方法,但它正在将类添加到父类中

<tabset justified="true" class="tab-nav">
       <tab heading="Justified">Justified content</tab>
       <tab heading="SJ">Short Labeled Justified content</tab>
       <tab heading="Long Justified">Long Labeled Justified content</tab>
</tabset>

正当内容
短标签对齐内容
长标签对齐内容

好的,ui引导模块不支持您不想做的事情,因此我们需要扩展该模块以获得请求的行为。为此,我们将使用装饰器:

.config(function($provide) {

  // This adds the decorator to the tabset directive 
  // @see https://github.com/angular-ui/bootstrap/blob/master/src/tabs/tabs.js#L88 
  $provide.decorator('tabsetDirective', function($delegate) {

    // The `$delegate` contains the configuration of the tabset directive as 
    // it is defined in the ui bootstrap module.
    var directive = $delegate[0];

    // This is the original link method from the directive definition
    var link = directive.link;

    // This sets a compile method to the directive configuration which will provide
    // the modified/extended link method
    directive.compile = function() {

      // Modified link method
      return function(scope, element, attrs) {

        // Call the original `link` method
        link(scope, element, attrs);

        // Get the value for the `custom-class` attribute and assign it to the scope.
        // This is the same the original link method does for the `vertical` and ``justified` attributes
        scope.customClass = attrs.customClass;
      }
    }

    // Return the modified directive
    return $delegate;
  });
});
这将采用tabset指令的旧
link
方法,并使用自定义方法对其进行包装,除旧方法外,自定义方法还将
自定义类的值绑定到范围。我们需要做的第二件事是重写模板以实际使用
scope.customClass
参数:

有多种方法可以使用
$templateProvider
或更简单的方法使用

  <script id="template/tabs/tabset.html" type="text/ng-template">
    <div>
      <ul class="{{customClass}} nav nav-{{type || 'tabs'}}" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" ng-transclude></ul>
      <div class="tab-content">
        <div class="tab-pane" ng-repeat="tab in tabs" ng-class="{active: tab.active}" tab-content-transclude="tab">
        </div>
      </div>
    </div>
  </script>


    Plunker

    好的,ui引导模块不支持您不想做的事情,因此我们需要扩展模块以获得请求的行为。为此,我们将使用装饰器:

    .config(function($provide) {
    
      // This adds the decorator to the tabset directive 
      // @see https://github.com/angular-ui/bootstrap/blob/master/src/tabs/tabs.js#L88 
      $provide.decorator('tabsetDirective', function($delegate) {
    
        // The `$delegate` contains the configuration of the tabset directive as 
        // it is defined in the ui bootstrap module.
        var directive = $delegate[0];
    
        // This is the original link method from the directive definition
        var link = directive.link;
    
        // This sets a compile method to the directive configuration which will provide
        // the modified/extended link method
        directive.compile = function() {
    
          // Modified link method
          return function(scope, element, attrs) {
    
            // Call the original `link` method
            link(scope, element, attrs);
    
            // Get the value for the `custom-class` attribute and assign it to the scope.
            // This is the same the original link method does for the `vertical` and ``justified` attributes
            scope.customClass = attrs.customClass;
          }
        }
    
        // Return the modified directive
        return $delegate;
      });
    });
    
    这将采用tabset指令的旧
    link
    方法,并使用自定义方法对其进行包装,除旧方法外,自定义方法还将
    自定义类的值绑定到范围。我们需要做的第二件事是重写模板以实际使用
    scope.customClass
    参数:

    有多种方法可以使用
    $templateProvider
    或更简单的方法使用

      <script id="template/tabs/tabset.html" type="text/ng-template">
        <div>
          <ul class="{{customClass}} nav nav-{{type || 'tabs'}}" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" ng-transclude></ul>
          <div class="tab-content">
            <div class="tab-pane" ng-repeat="tab in tabs" ng-class="{active: tab.active}" tab-content-transclude="tab">
            </div>
          </div>
        </div>
      </script>
    
    
    

      Plunker

      是否要将自定义类添加到
      而不是周围的
      ?您只需要为一个选项卡集或所有相同的选项卡集使用此选项,值需要是动态的还是静态的?@Numyx是的,我需要
        标记的自定义类。对于不同的选项卡集,我有不同的类。值是静态的。是否要将自定义类添加到
        而不是周围的
        ?您只需要为一个选项卡集或所有相同的选项卡集使用此选项,值需要是动态的还是静态的?@Numyx是的,我需要
          标记的自定义类。对于不同的选项卡集,我有不同的类。值是静态的。非常感谢您的回答。如果您能在每一行上简单的注释来解释以上配置代码,我将不胜感激。@Body在代码中添加了一些注释,希望它能帮助您理解。不幸的是,目前还没有关于如何使用装饰器的官方文档,我是从这篇文章中学到的:。非常感谢您的回答。如果您能在每一行上简单的注释来解释以上配置代码,我将不胜感激。@Body在代码中添加了一些注释,希望它能帮助您理解。不幸的是,(afaik)没有关于如何使用decorators的官方文档,我从本文中了解到:。