我需要通过ng-click来调用切换开关中的函数,但是 customerActiveDeactive 功能不会启动。
<a title="Active/ Deactivate" >
<input type="checkbox" class="js-switch" ng-init="status=True" ng-model="status" ng-name="status" ng-checked="{{ customer.status|lower }}" ng-click="customerActiveDeactive({{ customer.id }})" />
</a>
$scope.customerActiveDeactive = function(id) {
console.log("method call");
}
答案 0 :(得分:2)
您以错误的方式将变量作为参数传递: 这样做:
<a title="Active/ Deactivate" >
<input type="checkbox" class="js-switch" ng-init="status=True" ng-model="status" ng-name="status" ng-checked="{{ customer.status|lower }}" ng-click="customerActiveDeactive(customer.id )" />
</a>
$scope.customerActiveDeactive = function(id) {
console.log("method call");
}
答案 1 :(得分:1)
根据评论,由于客户id是您的django变量,只需更改此行:
ng-click="customerActiveDeactive({{ customer.id }})"
到
ng-click="customerActiveDeactive('{{ customer.id }}')"