I'm getting an error, random, sometimes occurs and sometimes not. I cannot identify the problem to fix.
Does anyone know the error cause or how to prevent?
My code:
angular.module('VigiApp').controller('FeedsController', ['$scope', 'gettextCatalog', 'FirebaseURL', '$ngBootbox', function($scope, gettextCatalog, FirebaseURL, $ngBootbox) {
$scope.contents = [];
isSpinnerBar(false);
$scope.init = function(){
isSpinnerBar(true);
// Get a database reference to our posts
//auth
var fbAuth = FirebaseURL.getAuth();
//Ref
var norm = new Firebase.util.NormalizedCollection(
FirebaseURL.child('contents'),
[FirebaseURL.child('categories'), 'category', 'contents.category_id']
);
// get a reference we can use like a normal Firebase instance
ref = norm.select('contents.category_id',
'contents.dt_created',
'contents.num_comment',
'contents.num_favorite',
'contents.text',
'contents.photos',
'contents.user_id',
{key: 'category.name.$value', alias: 'category_name'},{key: "category."+$scope.currentLanguage+".$value", alias: 'category_name_language'},{key: 'category.icon.$value', alias: 'category_icon'}).ref();
// Attach an asynchronous callback to read the data at our posts reference
ref.orderByChild("dt_created").limitToFirst(2).on("value", function(snapshot) {
console.log(snapshot.val());
var res = snapshot.val();
$scope.$apply(function() {
$scope.contents = res;
isSpinnerBar(false);
isButtonActivedFeed();
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
isSpinnerBar(false);
});
}
$scope.share = function(e){
}
}]);
The Warning:
FIREBASE WARNING: Exception was thrown by user callback. Error: [$rootScope:inprog] http://errors.angularjs.org/1.4.7/$rootScope/inprog?p0=%24digest
....
Ok, apologize for the post, I found a solution after much searching on google.
I was looking for firebase or firebase-util, but it is a mistake with my angular when navigating between pages.
The solution work for me:
var res = snapshot.val();
$timeout(function(){
$scope.$apply(function() {
$scope.contents = res;
isSpinnerBar(false);
isButtonActivedFeed();
});
});
solution, reason: AngularJS : Prevent error $digest already in progress when calling $scope.$apply()
Please, I'll keep the question if others have the same problem/doubt.