jordan jordan - 25 days ago 12
AngularJS Question

How to update the $scope variable values with the new Values I'm getting from the Database?

I have been setting the response values every time I hit the

web-service
to a
$scope
variable on click of a button but the
$scope
variable is not getting updated with the new values I have to Click the button twice so that the
$scope
variables get updated. also I have checked, each time I hit the button the
web-service
is properly getting called.

controller.js

$scope.getDetails = function() {
services.getSomeDetails($scope.id).then(function(response) {

$scope.details= response.data;

}
}


view.html

<a ng-click="getDetails();">Click me!</a>

Answer

Use $scope.$apply() after your scope Variable.

Comments