1.首先重复回顾一下ng-repeat指令
ng-repeat可以实现内容的重复显示,比如我们可以写如下代码
<script> angular.module("myapp",[]).controller("mycontroller",function($scope){ $scope.data=[{name:"yu1",age:10,partment:"产品部"}, {name:"yu2",age:11,partment:"产品部"}, {name:"yu3",age:12,partment:"事业部"}, {name:"yu4",age:13,partment:"事业部"}, {name:"yu5",age:14,partment:"物资部"}, {name:"yu6",age:15,partment:"物资部"} ] }) </script> <div> <table> <thead> <th>姓名</th> <th>年龄</th> <th>部门</th> </thead> <tbody> <tr ng-repeat="member in data"> <td>{{member.name}}</td> <td>{{member.age}}</td> <td>{{member.partment}}</td> </tr> </tbody> </table> </div>
显示效果如下:
2.此时的问题是,如果我们要删选的是部门为“产品部”的员工
那么可以使用ng-repeat+ng-if的方法,这样可以实现简单的前端删选
我们只需要在ng-repeat后面简单的加上ng-if="member.partment=='产品部即可'"
代码修改如下:
<tr ng-repeat="member in data" ng-if="member.partment=='产品部'">
效果为: