1

I need to call function in toggle switch by ng-click, but the customerActiveDeactive funtion is not fire.

<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 Answers 2

    2

    You are passing variable as a argument in wrong way: Do it like this:

    <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
    • {{ customer.id }} is my django variableCommentedJul 25, 2018 at 12:09
    • then store this variable in $scope.var="value" and then you can use var in html
      – Amrit
      CommentedJul 25, 2018 at 12:10
    1

    As per comments, since customer id your django variable, Simply change this line :

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

    to

    ng-click="customerActiveDeactive('{{ customer.id }}')" 
    4
    • {{ customer.id }} is my django variableCommentedJul 25, 2018 at 12:09
    • is customer.id variable is set as a scope variable?CommentedJul 25, 2018 at 12:10
    • {{ customer.id }} send to as parameter of customerActiveDeactive(id. isn't it?CommentedJul 25, 2018 at 12:11
    • @ShafikurRahmanShaon i have updated my answer please try with this change. :-)CommentedJul 25, 2018 at 12:12

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.