从AngularJS的Firebase实时更新信息 [英] Update infromation in Real-Time from Firebase in AngularJS
问题描述
这是我的角码:
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 ();
$ scope。$ apply();
if($ scope.value ==col6){
var currentMessageRef = rootRef.child ('currentMessage');
currentMessageRef.once(value,function(snapshot){
$ scope.html = snapshot.val(); $ b $ scope.trustedHtml = $ sce。 ($ scope);
});
} else if($ scope.value!=col6){
$ scope.html =db中没有值;
$ scope.trustedHtml = $ sce.trustAsHtml($ scope.html);
}
});
}]);
我在代码中插入发布信息的条件,但这并不重要...所有我想要的它是实时更新信息,无需重新加载我的网页。
感谢您的帮助!
函数一次
触发一次,然后不再触发。这就是为什么你的信息不会更新。在上使用代替订阅更改。更多信息: https://firebase.google.com/docs/database / web / retrieve-data#listen_for_events
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!
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
这篇关于从AngularJS的Firebase实时更新信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!