angular.js - Use ng-repeat to create list items in Angular. I want to hide the item by clicking on one of the list items. How to do this?
怪我咯
怪我咯 2017-05-15 16:49:24
0
2
965
<tr ng-repeat = "app in apps" ng-hide = "">
            <td>
                <a  data-uk-modal="{target:'#{{app._id}}'}">{{app.name}}</a>
            </td>
            <td>{{app._id}}</td>
            <td>{{app.author}}</td>
            <td>{{appCategoryMap[app.category].name}}</td>
            <td>
                <a  class="uk-button uk-button-danger" ng-click  = "underCarriage(app._id)">下架</a>
            </td>

        </tr>

How to write in ng-hide? If you write a variable, all list items will be the same ng-hide variable cannot hide a single

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
phpcn_u1582

Please describe your problem carefully, so that others will take your problem seriously.

You just want to click "Remove" and this row will disappear from the table. In fact, it is to delete a record in the data, AngularJS的绑定机制会自动的更新界面,这一行也就会自动消失了。不需要使用ng-hide.

You just need to implement it wellunderCarriage(app._id):

controllers.controller('SFTestCtrl', ['$scope', function($scope) {
  $scope.apps = [
    {
      _id: 0,
      name: 'test',
      author: 'test',
      category: 'test'
    },
    {
      _id: 1,
      name: 'test1',
      author: 'test1',
      category: 'test1'
    },
    {
      _id: 2,
      name: 'test2',
      author: 'test2',
      category: 'test2'
    }
  ];

  $scope.appCategoryMap = {
    test: {
      name: 'test'
    },
    test1: {
      name: 'test1'
    },
    test2: {
      name: 'test2'
    }
  };

  $scope.underCarriage = function(id) {
    $scope.apps.forEach(function(v, i, _) {
      if (v._id == id) {
        _.splice(i, 1);
      }
    });
  };

}]);

My local test can achieve the effect.

Peter_Zhu

Add a hidden attribute to apps to record whether it is hidden

http://jsfiddle.net/larvata/1wr2bfLs/

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template