角度转换选择值到 int [英] Angular cast select value to int

查看:24
本文介绍了角度转换选择值到 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有不同选择的表单,例如:

I have a form with different selects like :

<select [(ngModel)]="selected.isConnected" (ngModelChange)="formChanged()" name="etat" id="etat" class="form-control">
    <option value="0">Not connected</option>
    <option value="1">Connected</option>
</select> 

我的后端希望在isConnected"属性中收到一个整数.不幸的是,一旦我更改了 select 的值,该属性就会强制转换为字符串:

My backend expect to receive an int in the "isConnected" attribute. Unfortunately as soon as I change the value of the select the attribute is cast to a string :

{
    isConnected : "0", // 0 expected
}

对于标准 我可以使用 type="number" 但是对于

发送“验证码”获取 | 15天全站免登陆