2

I made a applicaion for show information from Firebase with AnguarJS. For this moment, information is updated after refresh page, but i want to update my information in real time.

Here is my angular code:

var root = angular.module('root',["services", "firebase"]); root.controller("root4",['$sce', "$scope", function($sce,$scope){ var ref = new Firebase("https://web-quickstart-8326d.firebaseio.com"); var locationRef = rootRef.child('location'); locationRef.once("value", function(snapshot) { $scope.value = snapshot.val(); $scope.$apply(); if($scope.value=="col6"){ var currentMessageRef = rootRef.child('currentMessage'); currentMessageRef.once("value", function(snapshot) { $scope.html = snapshot.val(); $scope.trustedHtml = $sce.trustAsHtml($scope.html); }); } else if($scope.value!="col6"){ $scope.html = "No value in db"; $scope.trustedHtml = $sce.trustAsHtml($scope.html); } }); }]); 

I insert in my code a condition for post information, but that's not important... all i want it's to update information in real time without reload my page.

Thank you for help!

4
  • Have you tried calling $scope.$apply() after assigning the scope variables that are not displayed in real time? See also stackoverflow.com/questions/38366955/… Commented Jul 14, 2016 at 9:32
  • $scope.apply(), it's just for identificate where it's neccessary to insert a message. Practically, message it's show in if condiion. I want to update just message. Thank you for reply! :) Commented Jul 14, 2016 at 9:35
  • @DiaconuEduard add your html plz. It will be so nice if you set up a jsFiddle as well. Commented Jul 14, 2016 at 14:47
  • @adolfosrs, thanks for reply. I successfully added the command for real time update. :) Have a nice day! Commented Jul 15, 2016 at 7:42

1 Answer 1

2

Function once triggers once and then doesn't trigger again. That's why your information doesn't update. Use on instead to subscribe on changes. More info here: https://firebase.google.com/docs/database/web/retrieve-data#listen_for_events

Sign up to request clarification or add additional context in comments.

1 Comment

That was! Thank you for help! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.