【问题标题】:when the value of ng-show is true then also element is not visible当 ng-show 的值为 true 时,元素也不可见
【发布时间】:2016-04-06 08:04:36
【问题描述】:

我正在尝试使用 ng-show 隐藏和显示选项卡。 我写了以下代码

 <li ng-show={{hidetabs}}  > <a data-toggle="tab" id="second_tab" href="#menu1">Customer Contacts</a></li>
            <li ng-show={{hidetabs}}> <a data-toggle="tab" id="third_tab" href="#menu2">CWC User Access</a></li>
      </ul> 

控制器的代码是 函数($scope,ngDialog,$routeParams,$window,$location){

                $scope.aircraftlist = [];

                $scope.hidetabs=false;



                $scope.aircraft = {};
                $scope.nextfirsttab = function() {
                    $scope.hidetabs=true;
                    $("#second_tab").click();
                }

问题是即使我将 hidetabs 的值设置为 true 类也是 ng-hide 。如果在 div 中放置 ng-show="hidetabs" 它根本不起作用。

【问题讨论】:

  • 您不需要花括号{{}},只需使用ng-show="hidetabs"。当需要大括号时,这可能会对explain 有所帮助。

标签: angularjs


【解决方案1】:

在引号内使用 ng-show 变量,也不需要插值

 <li ng-show="hidetabs"  > <a data-toggle="tab" id="second_tab" href="#menu1">Customer Contacts</a></li>
        <li ng-show="hidetabs"> <a data-toggle="tab" id="third_tab" href="#menu2">CWC User Access</a></li>
  </ul> 

【讨论】:

    【解决方案2】:

    hidetabs 中删除{{}}

    使用ng-show=hidetabs 代替ng-show={{hidetabs}}

    <ul>
    <li ng-show="hidetabs"> 
    <a data-toggle="tab" id="second_tab" href="#menu1">Customer Contacts</a></li>
    <li ng-show="hidetabs">
    <a data-toggle="tab" id="third_tab" href="#menu2">CWC User Access</a>
    </li>
    </ul>
    

    Plnkr 演示: http://plnkr.co/edit/q4eoglQUcxwNKvbjgQOF?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      相关资源
      最近更新 更多