oderfla
oderfla

Reputation: 1797

angularjs changes checkbox value from integer to boolean

I have some kind of repeat (its actually the grid-api that loops among elements). For each row I print a checkbox. In grid-api the element is referred as row.entity. Which is a json object.

Now, Im setting the ng-model equals to the id, like this:

ng-model="row.entity.id" 

I also print that ID on the screen, and it is a number. The ng-click looks like this:

ng-click="grid.appScope.addToQueue(row.entity.id, $event)"  

The function that handles the ng-click is this:

scope.addToQueue = function(id, $event){
     var element = angular.element($event.target);
     console.log("element:",element);
     console.log("id:",id);
  } 

The problem is that on the screen a number is printed. But as soon as I click in the checkbox, the value becomes a boolean, true or false. How can I get the actual number?
In the console it is the same problem. The boolean is printed.

Upvotes: 0

Views: 453

Answers (1)

Atural
Atural

Reputation: 5439

You should probably use data-ng-true-value and its counterpart data-ng-false-value.

E.g.

<input type="checkbox" ng-model="row.entity.id"  data-ng-true-value="1" data-ng-false-value="0" />

This is also very well documented on their documentation page. Take a closer look here.

Upvotes: 2

Related Questions