I am using a single page angular app for my blog. On load, the controller makes a call to my firebase for all blog posts and pushes them into a $scope.posts array. The HTML employs ng-repeat to display a snippet of each blog post. However, no snippets appear at all unless the user activates any other random function on the page to force the digest loop. How can I make it dirty check or force the digest loop without user interaction?
angular.module('evancodes.main', [])
.controller('MainController', function(Main, $http, $scope) {
$scope.posts = [];
$scope.getAllPosts = function() {
var ref = new Firebase("https://MYFIREBASENAME.firebaseio.com/");
ref.on("value", function(snapshot) {
var posts = snapshot.val();
for (var post in posts) {
$scope.posts.push(posts[post]);
}
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
$scope.getAllPosts();
})
HTML:
<div class="snippets col-md-9 col-md-offset-1" ng-repeat="post in posts | limitTo: 5">
<a href="#/posts/{{post.url}}">
<div class="snippetTitle">
{{post.title}}
</div>
<div class="snippetBody" ng-bind-html="post.content | limitTo: 650"></div>
</a>
</div>