Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output numeric from $scope in Angular

Tags:

angularjs

Is there a way to take form input numbers in this format within $scope:

From:

<input type="text" ng-model="form.octHours">

Which renders:

"form.octHours": "12"

And convert the format to numeric where controller data looks like this:

{
  data: [12]
}

Which will be used in the controller like this:

$scope.form = {}; 

$scope.data = {
    datasets:[    
        data: [$scope.form.octHours]
        ]
 }

I have tried using input type="numeric" and escaping the quotes via javascript, but is there an elegant way of doing this? Thank you...

like image 562
Fergus Avatar asked Jun 29 '26 23:06

Fergus


1 Answers

Have you tried injecting a filter into the controller then doing a string to it conversion?

 $scope.items = $filter('filter')($scope.items2, val);
like image 131
Angel Quicksey Avatar answered Jul 04 '26 21:07

Angel Quicksey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!