1

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 :/

serps
  • 221
  • 1
  • 4
  • 13
  • Have you searched before asking? http://stackoverflow.com/questions/14514461/how-can-angularjs-bind-to-list-of-checkbox-values I like to use the checklist-model directive – Gui Jul 11 '14 at 09:36
  • I always search before asking, thanks for the link i'll have a look – serps Jul 11 '14 at 09:42

2 Answers2

6

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

ThomasP1988
  • 4,597
  • 3
  • 30
  • 36
0

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);
};
Gianluca Mancini
  • 1,302
  • 9
  • 10
  • Thanks but i'm trying to get the value of the selected checkbox by using a this. which im thinking would mean that I dont need to create a model in my js file for every checkbox? – serps Jul 11 '14 at 09:41