Javascript 单选按钮使用ng值(angularjs)

Javascript 单选按钮使用ng值(angularjs),javascript,angularjs,Javascript,Angularjs,我是angularjs的新手。。 我想使用单选按钮进行选择,并另存为布尔值。 当我使用ng value时,保存到数据库中的值是null。这是html的代码 <label><input type="radio" ng-model="information" ng-value="TRUE" name="maklumat">Yes</label><br /> <label><input type="radio" ng-model="in

我是angularjs的新手。。 我想使用单选按钮进行选择,并另存为
布尔值。
当我使用
ng value
时,保存到数据库中的值是
null
。这是html的代码

<label><input type="radio" ng-model="information" ng-value="TRUE" name="maklumat">Yes</label><br />
<label><input type="radio" ng-model="information" ng-value="FALSE" name="maklumat">False</label>

假的
需要AngularJS表达式在选择收音机时将ngModel设置为哪个表达式

表达式区分大小写,如果设置
ng value=“true”
它会将
ng model
中的内容设置为
true
,但是如果设置了
ng value=“true”
,它会尝试获取未找到的
$scope.true
,而
ng model
会设置为
null

这里有一个例子

角度模块('radioExample',[]) .controller('ExampleController',['$scope',function$scope){ $scope.TRUE=“完全不同的东西” $scope.specialValue={ “id”:“12345”, “值”:“绿色” }; }]);

示例-示例无线电输入指令生成
特殊价值

真的
真的

颜色={{color.name | json}}



请注意,`ng value=“specialValue”`将单选项的值设置为“$scope.specialValue”的值。
问题在于您在
ng值中输入的内容
值,只需将其更改为小写即可

<label>
    <input type="radio" ng-model="information" ng-value="true" name="maklumat">Yes
</label>
<br />
<label>
    <input type="radio" ng-model="information" ng-value="false" name="maklumat">False
</label>

假的

编辑1


它之所以保存为null,是因为它试图计算未定义的值
FALSE

实际上,如果他想要布尔值,最好使用
ng value
,因为它将值执行为布尔值,而不是字符串。检查这个例子。为了在您链接的文档中对此进行扩展,它指出,如果您需要非字符串ngModel(布尔、数组等),则应使用ng value而不是value属性。此外,最好为controller中的
$scope.information=false
指定一个默认值(在这种情况下,数据将进入数据库)。