代码之家  ›  专栏  ›  技术社区  ›  shafik

AngularJS input field复选框ng click not firing method

  •  1
  • shafik  · 技术社区  · 8 年前

    我需要通过ng click调用toggle开关中的函数,但是 客户激活激活 功能不是火。

    <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");
    }
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   amrender singh    8 年前

    根据注释,由于customer id您的django变量,只需更改此行:

    ng-click="customerActiveDeactive({{ customer.id }})"
    

    ng-click="customerActiveDeactive('{{ customer.id }}')"
    
        2
  •  2
  •   Amrit    8 年前

    您以错误的方式将变量作为参数传递: 这样做:

    <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");
        }