【发布时间】:2014-11-15 09:07:41
【问题描述】:
我很困惑如何将 angularfire 的 syncArray 的 $loaded 承诺返回的原始数据绑定到 $scope,以防我不能简单地执行 ng-repeat。 我需要将原始数据传递给角度日历,并且没有 ng-repeat。
$scope.snapshot = fbutil.syncArray("snapshot/" + id)
$scope.events = []
$scope.snapshot.$loaded().then (entries) ->
angular.forEach entries, ((entry) ->
@push entry
return
), $scope.events
console.log "$scope.events: ", $scope.events
将输出到 $scope.events: [] 而不会将 promise 内部的可用条目数组绑定到 $scope。 它确实适用于 ng-repeat 为什么不通过这种方式?
【问题讨论】:
-
为什么要创建相同数据的静态(非同步)副本并将其放入同一个 $scope?这真的是你的意图吗?这看起来像 XY problem
-
这是正确的,我试图用一个监视函数来解决同步问题:snapshot.$watch(function(event) { if (!!event) { console.log(event); return $( "#calendar").fullCalendar("refetchEvents"); } });这种“单向数据绑定”在这里对我有用,因为我没有在日历上设置事件只是显示它们。我确实明白你对 xy 问题的看法,并将更改这篇文章的标题。
标签: angularjs coffeescript firebase angularfire