ng-click 仅在我没有模型时才有效
ng-click only works if I don't have a model
我的文件中有此代码
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><a ng-click="sort('PartnerName')">@TID.Partner</a></th>
<th><a ng-click="sort('StartTID')">@TID.StartTID</a></th>
<th><a ng-click="sort('EndTID')">@TID.EndTID</a></th>
<th><a ng-click="sort('DateBlocked')">@TID.DateBlocked</a></th>
<th><a ng-click="sort('Blocked')">@TID.Blocked</a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | orderBy:sortOrder:reverseSort | filter:refine | filter: { 'Blocked': showInactive!==true } as filtered ">
<td>{{ item.PartnerName }}</td>
<td>{{ item.StartTID }}</td>
<td>{{ item.EndTID }}</td>
<td>{{ item.DateBlocked }}</td>
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
</tr>
<tr ng-if="processed == false" ng-cloak>
<td colspan="5">@TID.Loading</td>
</tr>
<tr ng-if="filtered.length == 0 && processed == true" ng-cloak>
<td colspan="5">@TID.NoResultsFound</td>
</tr>
</tbody>
</table>
</div>
我有这个复选框
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
在我的控制器中调用此方法
$scope.UnBlockOne = function (item) {
db.UnBlockOne(item, function () {
$scope.GetFilteredList(filter);
$rootScope.processed = true;
});
};
奇怪的是,如果我有一个 ng-model,那么 ng-click 不起作用。
所以,这行得通
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model=""/></td>
这行不通
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
我在其他文件中也有这样的代码,并且工作正常。
这样试试,我不确定,因为我无法测试:
<td> <input type="checkbox" ng-click="UnBlockOne('item');" ng-model="item.Blocked"/></td>
$scope.UnBlockOne = function (item) {
db.UnBlockOne($scope['item'], function () {
$scope.GetFilteredList(filter);
$rootScope.processed = true;
});
};
但是对于复选框,您应该使用 ng-change。
您可能想看看 ng-change 而不是 ng-click
使用 ng-change 代替 ng-click。
参考:https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D
我的文件中有此代码
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><a ng-click="sort('PartnerName')">@TID.Partner</a></th>
<th><a ng-click="sort('StartTID')">@TID.StartTID</a></th>
<th><a ng-click="sort('EndTID')">@TID.EndTID</a></th>
<th><a ng-click="sort('DateBlocked')">@TID.DateBlocked</a></th>
<th><a ng-click="sort('Blocked')">@TID.Blocked</a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | orderBy:sortOrder:reverseSort | filter:refine | filter: { 'Blocked': showInactive!==true } as filtered ">
<td>{{ item.PartnerName }}</td>
<td>{{ item.StartTID }}</td>
<td>{{ item.EndTID }}</td>
<td>{{ item.DateBlocked }}</td>
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
</tr>
<tr ng-if="processed == false" ng-cloak>
<td colspan="5">@TID.Loading</td>
</tr>
<tr ng-if="filtered.length == 0 && processed == true" ng-cloak>
<td colspan="5">@TID.NoResultsFound</td>
</tr>
</tbody>
</table>
</div>
我有这个复选框
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
在我的控制器中调用此方法
$scope.UnBlockOne = function (item) {
db.UnBlockOne(item, function () {
$scope.GetFilteredList(filter);
$rootScope.processed = true;
});
};
奇怪的是,如果我有一个 ng-model,那么 ng-click 不起作用。
所以,这行得通
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model=""/></td>
这行不通
<td> <input type="checkbox" ng-click="UnBlockOne(item);" ng-model="item.Blocked"/></td>
我在其他文件中也有这样的代码,并且工作正常。
这样试试,我不确定,因为我无法测试:
<td> <input type="checkbox" ng-click="UnBlockOne('item');" ng-model="item.Blocked"/></td>
$scope.UnBlockOne = function (item) {
db.UnBlockOne($scope['item'], function () {
$scope.GetFilteredList(filter);
$rootScope.processed = true;
});
};
但是对于复选框,您应该使用 ng-change。
您可能想看看 ng-change 而不是 ng-click
使用 ng-change 代替 ng-click。
参考:https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D