角度条件ng-show按类别显示

时间:2015-07-03 16:48:40

标签: angularjs

我如何使用angularjs,ng-only只显示一次类别名称,如何指定一个先前类别的变量来匹配这个条件?

Eg. 
Animals, orc, sea;
Animals, dolphin, sea;
Animals, lion, land;
Fruits, apple, red;
Fruits, orange, citric;

<tr ng-repeat="singularitem in item ">
     <td ng-show="{{category != previous-category}}" colspan=2>{{ singularitem.Category }}</td>
            <td>{{ singularitem.Category }}</td>
            <td>{{ singularitem.Object}}</td>

1 个答案:

答案 0 :(得分:1)

您可以使用ng-init来完成此操作。见例子

<tr ng-repeat="singularitem in item ">
     <td ng-show="{{singularitem.Category != previous-category}}" ng-init="previous-category = singularitem.Category " colspan=2>{{ singularitem.Category }}</td>
            <td>{{ singularitem.Category }}</td>
            <td>{{ singularitem.Object}}</td>

在控制器中,您应首先将previous-category声明为空字符串变量。在您的控制器中执行

$scope.previous-category = '';