Currently, I am utilizing AngularJS within a Firebase application and have implemented a function that involves some inner join operations to retrieve data. Further information can be found here. Upon receiving the response from the Firebase API, I construct an object and add it to an array (a scope variable). While debugging, I confirm that the data has been successfully fetched and that the $scope variable is populated correctly. However, the issue arises when this information does not display in the ng-repeat section.
The following is my function:
$scope.getMessagesByRegion = function(regionId){
console.log('Function start');
var rootRef = firebase.database().ref();
var regionMessagesRef = rootRef.child("region_messages/"+ regionId);
$scope.messages_by_region = []; // Resetting the scope variable here
regionMessagesRef.on('child_added', function(rmSnap) {
var messageRef = rootRef.child("messages/"+rmSnap.key);
messageRef.once('value').then(function(msgSnap){
var msg = {
key : msgSnap.key,
name : msgSnap.val().name,
type : $scope.getTypeName(msgSnap.val().type),
show_only_once : rmSnap.val().show_only_once,
pre_requisite_message : rmSnap.val().pre_requisite_message
}
console.log(msg); // Object shown in console - all good
$scope.messages_by_region.push(msg);
console.log('----------------');
console.log($scope.messages_by_region);
})
});
}
This is what appears in my HTML:
<table class="table">
<thead>
<tr>
<th>Message name</th>
<th>Type</th>
<th>Show only once</th>
<th>Pre requisite</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="msg in messages_by_region">
<td ng-bind="msg.name"></td>
<td ng-bind="msg.type"></td>
<td ng-bind="msg.show_only_once"></td>
<td ng-bind="msg.pre_requisite_message"></td>
</tr>
</tbody>
</table>
In the console log output: [Link to screenshot](https://i.sstatic.net/6a25a.png)
Despite having objects within the array, they are not displaying on the view. It seems as though there's an empty array assigned to the $scope.messages_by_region
variable.
I'm struggling to identify where the error lies in my function. Can anyone spot what might be causing the problem?
Any assistance would be greatly appreciated. Thank you.