serps
serps

Reputation: 221

Can you get this ng-model value from ng-click?

I have several checkboxes in angular.js and I am trying to get the ng-model value from the selected checkbox when clicked. Any suggestions?

<div class="checkbox">
    <label>
    <input type="checkbox" ng-model="hyp" value="false" ng-click="selection($event)">
                    Hypertension
    </label>
</div>


$scope.selection = function($event){

    console.log($event.target.value);
}

I hope that this is clear enough :/

Upvotes: 1

Views: 1187

Answers (2)

Gianluca Mancini
Gianluca Mancini

Reputation: 1312

You can get the value directly from the model. So you can do this:

$scope.hyp = false;  // You can remove the value attribute
$scope.selection = function() {
  console.log($scope.hyp);
};

Upvotes: 0

t0mpl
t0mpl

Reputation: 5025

you can directly put your model inside your function : ng-click="selection(hyp)"

Upvotes: 6

Related Questions