Jenson Raby
Jenson Raby

Reputation: 789

ng-change value not getting in angular controller

In html

<input type="number" min="0" max="1000" class="form-control" ng-model="eachvalue.hours" ng-change="updateHour(eachvalue);" placeholder="Hours" required>

In Controller

 $scope.updateHour = function (val) {
    console.log(val);
  }

I m not getting the value of 10.100 on controller when changing the number text box , here i can only console the value of 10.1

Can anyone know how to resolve the issue ?????????

Upvotes: 0

Views: 66

Answers (3)

Denis Thomas
Denis Thomas

Reputation: 1022

You could try to define eachvalue.hours like that so you can bind to it:

$scope.eachvalue = { hours: 0 };

Upvotes: 0

Gayathri Mohan
Gayathri Mohan

Reputation: 2962

you can change your HTML also instaed

ng-change="updateHour(eachvalue)

TO

ng-change="updateHour(eachvalue.hours)

Upvotes: 0

MattDiMu
MattDiMu

Reputation: 5013

By using ng-model, the value is already (two-way-)bound to $scope.eachvalue.hours. It will always be up-to-date, no need to use ng-change and pass a value to it.

 $scope.updateHour = function () {
  console.log($scope.eachvalue.hours);
 }

Upvotes: 1

Related Questions