简体   繁体   English

动态更改uib-tabset属性中的值

[英]Dynamically change value in uib-tabset attribute

In my project I use ui.bootstrap.tabs . 在我的项目中,我使用ui.bootstrap.tabs On md and lg screens tabs should appear vertically stacked, but on screens sm and xs I want to see them appear horizontally. mdlg屏幕上,选项卡应垂直堆叠显示,但在smxs屏幕上,我想看到它们水平显示。 All I need is to set value in vertical attribute either true or false. 我需要做的是在vertical属性中设置true或false的值。 When screen size is changed, I have match on md or lg sizes and set property vertical_tab_appearance = true and the same with sm and lg sizes, property has false value, but uib-tabset directive does not know that the value of that property has changed. 当屏幕尺寸更改时,我在mdlg尺寸上具有匹配项,并将属性vertical_tab_appearance = true设置为与smlg尺寸相同的属性具有false值,但是uib-tabset指令不知道该属性的值已更改。

 <div class="col-md-2 small hidden-print">
        <div ng-model="value">
            <uib-tabset vertical="vertical_tab_appearance" type="pills"> 
                <uib-tab></uib-tab>
            </uib-tabset> 
        </div>
</div>

Here is my screen size events: 这是我的屏幕尺寸事件:

 screenSize.on('md, lg', function (match) {
   if (match) {
       $scope.vertical_tab_appearance = true;
   }
  });

 screenSize.on('sm, xs', function (match) {
   if (match) {
       $scope.vertical_tab_appearance = false;
    }
  });

Can I do something here or I should use ng-if in this situation? 我可以在这里做些什么,还是在这种情况下应该使用ng-if

If someone else will face the same problem, here is a solution. 如果其他人也会遇到相同的问题,这是一个解决方案。 I decided to use uibTabsetDirective decorator in module config and add watcher to a vertical attribute in a linking function. 我决定在模块配置中使用uibTabsetDirective装饰器,并将监视程序添加到链接函数中的vertical属性中。

.config(function ($provide) {
            $provide.decorator('uibTabsetDirective', function($delegate) {
                var directive, link, scope;
                directive = $delegate[0];
                link = directive.link;
                scope = directive.scope;
                scope['vertical'] = '=';
                directive.compile = function() {
                  return function Link(scope, element, attrs, ctrls) {
                    scope.$watch(attrs.vertical, function() {
                        console.log(scope.vertical);
                    });

                    return link.apply(this, arguments);
                  };
                };
                return $delegate;
            });
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM