2

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

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Dino
  • 7,779
  • 12
  • 46
  • 85

1 Answers1

1

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

xsong
  • 630
  • 1
  • 5
  • 18
  • This will just parse myNumb as a string. – Dino Oct 09 '17 at 10:17
  • 1
    read the [document](https://www.primefaces.org/primeng/#/checkbox) and try add `binary` to true – xsong Oct 09 '17 at 10:30
  • if its not work when added the binary, you can warpper `p-checkbox` component to a new component and translate the value in your new component. good luck. – xsong Oct 09 '17 at 10:41