Firebase.ServerValue.TIMESTAMP 在视图中显示为 {".sv":"timestamp"} with .push()

Firebase.ServerValue.TIMESTAMP displayed in view as {".sv":"timestamp"} with .push()

我的控制器中有以下功能:

  $scope.add = function(newItem){
    if (!(newItem.title && newItem.text)) return;
    var sanitized = {
      title: newItem.title,
      text: newItem.text,
      date: Firebase.ServerValue.TIMESTAMP,
    };
    // $rootScope.currentUser is here bound with $firebaseObject(ref).$bindTo($rootScope, 'currentUser').
    $rootScope.currentUser.list.push(sanitized);
    // .list is an array: []. 
  };

在我看来,我是这样使用它的:

    <form name="newUp">
        <input ng-model="newItem.title">
        <textarea ng-model="newItem.text"></textarea>
        <button ng-click="add(newItem)">Submit</button>
    </form>

    <div ng-repeat="item in currentUser.list | orderBy:'-date'">
     <p>
      <span><a href="">{{item.title}}</a> <small>  -&nbsp;&nbsp;{{item.date | date:'d MMM yy'}}</small></span><br>
      <span ng-if="item.text"><small>{{item.text}}</small></span>
     </p>
    </div>

但是在点击提交按钮并将项目保存到 firebase 数据库后,它在屏幕上显示为:

{".sv":"timestamp"}

在我完全刷新页面后,它显示了具有正确时间戳的项目。有没有办法避免这种情况?我可以避免使用 $firebaseArray 来解决这个问题吗?

我使用的是 bower,它已经降低了以下版本:

来自 $firebaseObjectquick glance there is a bug 作品。很明显,它没有正确处理特殊对象 Firebase.ServerValue.TIMESTAMP 的值,该对象告诉服务器将时间戳 放在服务器端 。但是,使用同步方法 $add.

将相同对象添加到 $firebaseArray 时情况并非如此

也许我缺少 $firebaseObject 的某种 flush 方法,但我找不到它。

无论如何你应该使用$firebaseArray因为你的数据是Array类型。并且不要忘记根据 docs

使用 $add$save$remove