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");
    }
Sign up to request clarification or add additional context in comments.

2 Comments

{{ customer.id }} is my django variable
then store this variable in $scope.var="value" and then you can use var in html
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 Comments

{{ customer.id }} is my django variable
is customer.id variable is set as a scope variable?
{{ customer.id }} send to as parameter of customerActiveDeactive(id. isn't it?
@ShafikurRahmanShaon i have updated my answer please try with this change. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.