I am facing an issue of converting string value to numbers when i pass into my input field. I have used parseInt but instead getting an NAN value .
Here is my input field in html:
<div class="row">
<div class="col-md-12">
<div class="form-group col-md-6">
<label>Form id:</label>
<input type= "text" name="fromId" class="form-control" ng-model="IssueReceipt.formId" ng-required="true" readonly> <span class="error" ng-show="issueReceiptDataEntryform.fromId.$dirty && issueReceiptDataEntryform.fromId.$error.required "></span>
</div>
And my script page where i pass the value :
$scope.getRandomForm = function() {
paymentService.NewEReceipt().success(function(data){
console.log(data)
$scope.IssueReceipt.formId = parseInt(data);
console.log(parseInt(data));
})
}
$scope.getRandomForm()
Let me show u the console i'm getting :
If i use parseInt, i'm getting NAN as the value instead of number. Please can anyone help me with this ?
trim
ing thedata
before parsing to int. I dont see something wrong with the code as well as the value. – Jaganathan Bantheswaran 1 hour agodata
is string. The reason i told you to trim the stringdata
is to avoid the space if any in the string. Try like thisparseInt(data.trim())
– Jaganathan Bantheswaran 42 mins ago