Angularjs scope variable not updating


Angularjs scope variable not updating in view | Controller – Sometimes we face issue with angularjs Scope variable like variables are not updated in view or controller. You can fix this problem simply using the $scope.apply()method just after the scope variables initializations. Here in this tutorial we are going to explain how you can fix this issue quickly.


Angularjs scope variable not updating in View | Controller

Just add $scope.apply(); after the variable values are updated.

Angularjs scope variable not updating:

$scope.apply();

Example –

Here is an example which shows how you can use $scope.apply(); in angularjs –

Angularjs scope variable not updating in view controller

$scope.title = "New Title";
$scope.name = "New Name";
$scope.apply(); // will fix your problem.

If the variables $scope.title and $scope.name are not updated $scope.apply() will force them to aplly the new updated values. Hope this will help your problem.


Advertisements

Add Comment

📖 Read More