Dino
Dino

Reputation: 8292

PrimeNG - Checkbox value as number

I am using primeng checkbox. I am trying to add number to the 'value' property of p-checkbox.

<p-checkbox value={{myNumb}} [(ngModel)]="rowData.enabled"></p-checkbox>

myNumb: number = 1;

Even though myNumb is set to a number, and rowData.enabled is also number, once the checkbox is checked, rowData.enabled will look like this:

enabled: ["1"]

I have also tried with the normal checkbox as:

<input type="checkbox" value="1" [(ngModel)]="rowData.enabled">

but in this case, it seems like that ngModel ignores the value and uses the boolean true / false.

So I get

enabled: true

I could use any of these cases, as long as I get

enabled: 1

EDIT: I changed value to [value] and now I'm getting number, but it's in array

enabled: [1]

Is this the default behaviour of ? That it stores the values in arrays

Upvotes: 2

Views: 9091

Answers (1)

xsong
xsong

Reputation: 670

try <p-checkbox [value]="myNumb" [(ngModel)]="rowData.enabled"></p-checkbox>

Upvotes: 1

Related Questions