[英]How to compare for two different objects inside ng-repeat
What is the best way to compare two different objects for equality inside of ng-repeat, why doesn't angular.equals work for me here: 比较ng-repeat中两个不同对象的相等性的最佳方法是什么,为什么angular.equals在这里对我不起作用:
<tr ng-repeat="row in ctrl.filteredItems" ng-class="{'active':angular.equals(row,ctrl.ngModel), 'focus': angular.equals(row,ctrl.focusedRow)}">
<td ng-repeat="value in ctrl.sort(row) track by $index" class="text-center">
{{value}}
</td>
</tr>
I want to add the active class if the current row and the pre-selected row coming from the controller match. 如果当前行和来自控制器的预选行匹配,我想添加活动类。
Write a function in JS which will do angular.equals(obj1, obj2) and use this function to check is it active or not? 在JS中编写一个函数,该函数将执行angular.equals(obj1,obj2)并使用此函数检查其是否处于活动状态?
HTML 的HTML
<tr ng-repeat="row in ctrl.filteredItems" ng-class="{'active': checkEqualiy(row, ctrl.ngModel), 'focus': checkEquality(row,ctrl.focusedRow)}">
<td ng-repeat="value in ctrl.sort(row) track by $index" class="text-center">
{{value}}
</td>
</tr>
JS JS
$scope.checkEquality= function(param1, param2){
return angular.equals(param1, param2)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.