Why doesn't Angular update the scope here?

I am new to Angular and I use firebase as my backend. I was hoping someone could debug this problem. When I first go to my page www.mywebsite.com/#defaultHash , the data is not loaded into the DOM, this happens after visiting another hash link and returning back.

My controller looks like this:

/* initialize data */

var fb = new Firebase('https://asdf.firebaseio.com/');

/* set data to automatically update on change */

fb.on('value', function(snapshot) {

  var data = snapshot.val();
  $scope.propertyConfiguration = data.products;
  console.log($scope.propertyConfiguration);
  console.log("Data retrieved");

});

/* save data on button submit */

$scope.saveConfigs = function(){

  var setFBref = new Firebase('https://asdf.firebaseio.com/products');
  setFBref.update($scope.propertyConfiguration);
  console.log("configurations saved!");

};

I have three hash routes: General, Registration, and Home, otherwise .redirectTo is set to Shared. (They all use this controller). Here an error occurs: (all "links" are href = "# hashWhereever")

1) website.com/#Shared . $scope.propertyConfiguration "Data Retrieved". DOM .

2) website.com/#Registration, , DOM .

3) website.com/#Shared, , DOM .

4) website.com/#Shared. DOM .

$scope.data , Angular , DOM ? DOM , .

"" , window.location.hash = "Shared", .

:( )

$scope. $apply() . , , , $scope. Angular " " , , , $scope overqualify?

+1
1

Angular , $scope.variable. . (ng-click/ng-submit) Angular, $apply() ( ).

, , $apply, $timeout. , Firebase, (child_added, child_changed, value ..). , $apply, $apply. , . $timeout .

, $timeout.

Angular , ; Angular.

, , Firebase Angular, .

: Angular Object.observe magic .

+2

Source: https://habr.com/ru/post/1569456/


All Articles