CraZyDroiD
CraZyDroiD

Reputation: 7105

access checkbox value in controller

I'm trying to access the checkbox value from my angularjs controller.

My checkbox is as follows.

  <div class="checkbox"><label for="id_tokenization">
   <input ng-click="addProperties()" name="tokenization" type="checkbox" ng-model="vault.tokenization" value="store.preauth.approved_responses">
   Enable Tokenization</label></div>
  </div>

For my checkbox value i have given a string. I want to get that value to my controller. How can i do this?

Upvotes: 0

Views: 2033

Answers (3)

piemesson
piemesson

Reputation: 44

Try using the angular notation {{ }} which we use to refer the controller's data into model. However make sure you have declared this into your controller.

 <input ng-click="addProperties()" name="tokenization" type="checkbox" ng-model={{vault.tokenization}} value="store.preauth.approved_responses">

Upvotes: 0

Jigar7521
Jigar7521

Reputation: 1579

You can do something like this :

  <div class="checkbox"><label for="id_tokenization">
   <input ng-change="addProperties(store.preauth.approved_responses)  name="tokenization" type="checkbox" ng-model="vault.tokenization" ng-value="store.preauth.approved_responses">
   Enable Tokenization</label></div>
  </div>

And in your controller, you can check whether it was checked or not and if its been checked you can define your action over there :

$scope.addProperties = function(prod){
    var index = $scope.selected_products.indexOf(prod.name);
    if(index == -1 && prod.selected){
      $scope.selected_products.push(prod.name);
    } else if (!prod.selected && index != -1){
      $scope.selected_products.splice(index, 1);
    }
  }

Upvotes: 0

M. Junaid Salaat
M. Junaid Salaat

Reputation: 3783

You can simply pass in the modal value on your ng-click attribute as parameter like

ng-click="addProperties(vault.tokenization)"

similarly in your markup

<input ng-click="addProperties(vault.tokenization)" name="tokenization" type="checkbox" ng-model="vault.tokenization" value="store.preauth.approved_responses">

Upvotes: 3

Related Questions