简体   繁体   English

使用angularjs切换列表项的显示/隐藏

[英]toggle show/hide of list items using angularjs

 var myApp = angular .module("myApp", []) .controller("listController", function($scope) { var foodList = [ { name : 'Hyderbadi Koma', types : [ { name : "sweet" }, { name : "extra chatpata" }, { name : "chatpata" } ], flag: 0 }]; ... $scope.showhide = function(foodLists) { if (foodLists.flag == 0) foodLists.flag++; else foodLists.flag--; }; }); 
 ... <td class="leftSection"> <ul> <li ng-repeat="foodItem in foodList" ng-click="showhide(foodItem)" class="clic"> {{ foodItem.name }} <ul> <li ng-repeat="foodType in foodItem.types" ng-hide="{{ foodItem.flag | filtering }}" class="unclic"> {{ foodType.name }} ///For watching variable flag {{foodItem.flag}} </li> </ul> </li> </ul> ... 
Now here after tracing i found that "ng-click" is performing its action of changing the flag value from 1 to 0 and vice versa. 现在,在跟踪之后,我发现“ ng-click”正在执行将标志值从1更改为0的操作,反之亦然。 Though I am not able to debug why ng-hide is not performing its action simultaneously, please help! 虽然我无法调试ng-hide为什么不能同时执行其动作,但请帮忙!

try this... 尝试这个...

<td>
      <ul ng-repeat="foodItem in foodList">
        <li class="clic">
          <a href="#" ng-click="showhide(foodItem)"> {{ foodItem.name }}</a>

            <ul ng-repeat="foodType in foodItem.types">
              <li  ng-hide="{{ foodItem.flag}}" class="unclic">
                {{ foodType.name }}
              </li>
            </ul>
        </li>
      </ul>
    </td>

https://plnkr.co/edit/sTWHI3SQeKgNN7QoOrrw https://plnkr.co/edit/sTWHI3SQeKgNN7QoOrrw

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

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