angularjs - How to assign Boolean value to model -
i have following view 2 input radio buttons:
<label> <input type="radio" name="test" ng-model="foobar" value="true" ng-change="logconsole()"> true </label> <label> <input type="radio" name="test" ng-model="foobar" value="false" ng-change="logconsole()"> false </label>
and controller looks like:
//initialization $scope.foobar = false; $scope.logconsole = function () { console.log("value : " + $scope.foobar); console.log("type : " + typeof $scope.foobar); //always displays 'string' };
my problem when user selects either of radio buttons, type of foobar
model string, value either string 'true' or string 'false' - want type boolean true value or boolean false value. how can store boolean value (from within view) onto model?
edit: tried out , still not work. value
attribute, passed function return boolean true or false, this:
<input type="text" value="{{getboolean('true')}}....>
$scope.getboolean = function (value) { if (value === 'true') return true; else return false; };
it still results in string when radio buttons selected...
one of comments in the documentation says:
while ng-value not documented, useful directive, when binding boolean value.
<input ng-model="foo" type="radio" value="true">
may not work
<input ng-model="foo" ng-value="true" type="radio">
does.
Comments
Post a Comment