mkteagle
mkteagle

Reputation: 579

Not updating view from Angularfire

Lets try to make this as simple as possible. My view is not updating although changes are getting up to Firebase. I have tried to use callback functions here and there to no luck and it doesn't seem like they are needed here, but my view isn't updating until after the page refreshes. I am trying to implement a counter every time a button is clicked.

View

//The selected is just because I needed to select the key to show the correct
//values in the view
<div class="row"><div class="onehundred">{{hc.selected.counter}}</div>
<span class="onehundreddonuts"> donuts</span></div>

Controller

function incrementCounter() {
//I have tried wrapping this in a .then(function(){}) callback function based 
//on the self.player.$loaded() but this doesn't fix anything, so I took it out
//for simplicity. If I console.log my self.player = homeService.player array
//it prints it out correctly anyway.

homeService.incrementCounter();
}

Service

function incrementCounter() {
self.counter ++;
self.update();

}
function update() {
self.player.$save(key);
}

Upvotes: 0

Views: 108

Answers (1)

jbdev
jbdev

Reputation: 751

I've found this can help in similar situations:

$timeout(function() {
    $scope.$apply();
});

Upvotes: 0

Related Questions