[英]Load data from Firebase using AngularJS immediately
我正在尝试在我的网站上发表评论部分。 我已经正确链接了我所有的文件,并且可以从Firebase获取数据。 但是,只有在我单击某些内容或在“添加评论”字段中输入文本后 ,评论才会加载; 当页面加载时,它不会立即显示评论。 有人知道为什么吗?
相关代码:(放在控制器的顶部)
$scope.comments = {};
database.ref('comments').on('value', function(items) {
$scope.comments = items.val();
});
$scope.comment = function() {
database.ref('comments').push($scope.newComment);
$scope.newComment = "";
};
使用$ scope。$ apply
$scope.comments = {};
database.ref('comments').on('value', function(items) {
$scope.$apply(function () {
$scope.comments = items.val();
});
});
$scope.comment = function() {
database.ref('comments').push($scope.newComment);
$scope.newComment = "";
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.