简单的html:
<table class="table table-condensed">
<tr data-ng-repeat="customer in customers" data-ng-class="customerSelectedClass(customer)">
<td>
<a href="" data-ng-click="selectCustomer(customer)">{{customer.Name}}</a>
</td>
</tr>
</table>
在我的控制器中-选择客户并返回适当的类以突出显示表格行的两个功能:
$scope.customerSelectedClass = function (customer) {
if (customer == $scope.selectedCustomer) {
console.log('returing info for ' + customer.Name);
return "info";
}
return "";
};
$scope.selectCustomer = function (customer) {
console.log('selecting ' + customer.Name);
$scope.selectedCustomer = customer;
}
我注意到当我单击客户链接时,customerSelectedClass 函数执行了两次。ng-click 指令上的 selectCustomer 函数应该执行一次。Angular 在页面上只包含一次。我想知道这是 Angular 中的错误还是我做错了什么?