javascript - Use ng-value for radio button (angularjs) -
i'am new angularjs.. want make selection using radio button , save boolean
value. when use ng-value
, value save database null
. code 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>
ng-value
expects angularjs expression ngmodel be set when radio selected.
and expressions being case-sensitive, if set ng-value="true"
sets have in ng-model
true
, if have ng-value="true"
, tries $scope.true
doesn't find , ng-model
gets set null
.
here's example.
angular.module('radioexample', []) .controller('examplecontroller', ['$scope', function($scope) { $scope.true = "something totally different" $scope.specialvalue = { "id": "12345", "value": "green" }; }]);
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>example - example-radio-input-directive-production</title> <script src="//code.angularjs.org/snapshot/angular.min.js"></script> </head> <body ng-app="radioexample"> <form name="myform" ng-controller="examplecontroller"> <label> <input type="radio" ng-model="color.name" ng-value="specialvalue"> specialvalue </label><br/> <label> <input type="radio" ng-model="color.name" ng-value="true"> true </label><br/> <label> <input type="radio" ng-model="color.name" ng-value="true"> true </label><br/><br/> <tt>color = {{color.name | json}}</tt><br/> </form> <br><br/><br/> note `ng-value="specialvalue"` sets radio item's value value of `$scope.specialvalue`. </body> </html>
Comments
Post a Comment