Nader Nader - 5 months ago 30
AngularJS Question

AngularJS not showing data when promise resolves

My table won't display the data it receives after a promise resolves. The data, however, is shown after a filter query is updated.


let app = angular.module("tierlist", []);

app.controller("tierListController", function ($scope, $http) {

firebase.database().ref('/Primaries/').once('value').then(function (snapshot) {

$scope.Primaries = $.map(snapshot.val(), function (element) {
return element;



<div class="container tiertab" id="Primaries">
<table id="primariesTable" class="table table-condensed table-responsive sortable">
<th onclick="sortTable('primariesTable', 0)">Rank</th>
<th onclick="sortTable('primariesTable', 1)">Weapons</th>
<th onclick="sortTable('primariesTable', 2)">Primary DMG Type</th>
<th onclick="sortTable('primariesTable', 3)">CC Mechanic</th>
<th onclick="sortTable('primariesTable', 4)">MR Req</th>
<th>Base or Event Rankings</th>
<th>Suggested Builds</th>
<tr class="sortable" ng-repeat="primary in Primaries | filter: $ctrl.query" >

I believe I'm doing something wrong as far as the controller is involved. If the data is associated with the given fields, why would the data not display after resolving the promise?

Answer Source

When $scope bound data is updated asynchronously angular doesn't update the view because it doesn't know when this is going to happen. Your data could be being updated when filtering since angular is internally triggering $scope.$digest(). You could try:

$scope.$evalAsync(function () {
    $scope.Primaries = $.map(snapshot.val(), function (element) {
        return element;

This should update the view. $evalAsync was introduced in angularjs 1.2 but you can use $scope.$apply if the version you are using is older. This post has great info on the difference between both:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download