search

Home  >  Q&A  >  body text

angular.js - Problems using ng-hide in angularjs.

<p class="原有的class" ng-hide=“{{item.amount}}=0” ng-repeat=“item in items track by $index”>
具体内容
</p>

item.amount is the quantity of the product. It will be dynamically modified when you click -.
This picture is the specific application scenario. When you click -, when it is equal to 0, you need to hide the p. The current situation is You can hide it by refreshing the page or jumping back, but you can't hide it immediately when you click -. Please tell me how to solve it. Because it is a list produced by ng-repeat, ng-hide cannot directly pass a Boolean value. Is there any other way to solve it?

某草草某草草2817 days ago578

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-15 16:58:13

    用ng-hide="item.amount==0"

    var app = angular.module('plunker', []);
    
    app.controller('MainCtrl', function($scope) {
      $scope.name = 'World';
      $scope.items = [{amount:0}];
      
      $scope.minus = function(){
        --$scope.items[0].amount;
      }
    });
    
      <body ng-controller="MainCtrl">
        <p ng-hide="item.amount==0" ng-repeat="item in items track by $index">
          {{item.amount}}
        </p>
        <button ng-click="minus()">-</button>
      </body>

    http://plnkr.co/edit/7KeNE5BtMJvRmjrafcr0

    reply
    0
  • 某草草

    某草草2017-05-15 16:58:13

    ng-hide=“item.amount==0”

    reply
    0
  • Cancelreply