I've been trying to figure this out for a couple of days now...
I've got a set of radio buttons to rate something between 1 and 5 with each set to value = 1, value = 2 and so on as part of a comment form. But when the data is returned to the controller and is pushed to the db.json file, the radio button values are of type string. How do I get them to be of type int?
Radio button HTML code:
<label class = "radio-inline" for = "one"><input type = "radio"
name = "rating" id = "one" data-ng-model = "userComment.rating"
value = 1 required>1</label>
code from controllers.js:
$scope.submitComment = function() {
$scope.movie.comments.push($scope.userComment);
myFactory.getMovies().update({id:$scope.movie.id}, $scope.movie);
I tried this thinking it would work, but it didn't.
$scope.userComment.rating = parseInt($scope.userComment.rating);
Simply try to use ng-value instead of value attribute:
<label class = "radio-inline" for = "one"><input type = "radio"
name = "rating" id = "one" data-ng-model = "userComment.rating"
ng-value = "1" required>1</label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With