简体   繁体   English

PrimeNG - 复选框值作为数字

[英]PrimeNG - Checkbox value as number

I am using primeng checkbox.我正在使用 Primeng 复选框。 I am trying to add number to the 'value' property of p-checkbox.我正在尝试将数字添加到 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:即使 myNumb 设置为数字,并且 rowData.enabled 也是数字,但选中复选框后,rowData.enabled 将如下所示:

enabled: ["1"]启用:[“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.但在这种情况下,ngModel 似乎忽略了该值并使用布尔值 true/false。

So I get所以我得到

enabled: true启用:真

I could use any of these cases, as long as I get我可以使用这些案例中的任何一个,只要我得到

enabled: 1启用:1

EDIT: I changed value to [value] and now I'm getting number, but it's in array编辑:我将值更改为 [value],现在我得到了数字,但它在数组中

enabled: [1]启用:[1]

Is this the default behaviour of ?这是默认行为吗? That it stores the values in arrays它将值存储在数组中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM