Devesh Agrawal Devesh Agrawal - 11 months ago 39
AngularJS Question

view is not updating after change in scope variable angular js

This is my code to get the data from server.

sampleApp.controller('OfferController', function ($scope, $state) {

var offersRef = firebase.database().ref('offers');
$scope.offers = [];

offersRef.on('value', function(snapshot) {
$scope.offers = snapshot.val();
//$state.go($state.current, {}, {reload: true});


Initially $scope.offers = []; is empty. It is getting filled up here. $scope.offers = snapshot.val();

But view is not updating. if i click any button or anything there on the same page, or go back and come again on same page. its getting updated.

Why is not getting updated as soon as data in available? How to fix?


Call $scope.$apply(); after setting the value to update the binding after setting the value.

$scope.offers = snapshot.val();