Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Angular Firebase 3路数据绑定正确同步采集?_Javascript_Angularjs_Firebase_Angularfire - Fatal编程技术网

Javascript 如何使用Angular Firebase 3路数据绑定正确同步采集?

Javascript 如何使用Angular Firebase 3路数据绑定正确同步采集?,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,我使用的是角度、Firebase和3向数据绑定 我还使用了过滤器,因此活动项目(状态1)列在顶部,暂停项目(状态2)列在底部。当然,这只是过滤的一个示例: 当使用Angular和Firebase的3路绑定时,似乎会产生奇怪的结果 1.将新项目添加到集合时,集合上的所有其他项目将临时消失。为什么? 下面是一些重要的代码: $scope.firebaseURL = "https://flickering-date.firebaseio-demo.com/"; $scope.todos = [

我使用的是角度、Firebase和3向数据绑定

我还使用了过滤器,因此活动项目(状态1)列在顶部,暂停项目(状态2)列在底部。当然,这只是过滤的一个示例:

当使用Angular和Firebase的3路绑定时,似乎会产生奇怪的结果

1.将新项目添加到集合时,集合上的所有其他项目将临时消失。为什么?
  • 下面是一些重要的代码:

    $scope.firebaseURL = "https://flickering-date.firebaseio-demo.com/";
    $scope.todos = [
        {name: 'post to stack overflow', state: 1, dateAdded : new Date(2013,1,1)}, 
        {name: 'plunker', state: 2, dateAdded : new Date(2013,2,2)},
        {name: 'github', state: 3, dateAdded : new Date(2013,3,3)},
        {name: 'mailing list', state: 1, dateAdded : new Date(2013,4,4)}
    ];
    $scope.state = 1;
    
    $scope.$firRef = $firebase(new Firebase($scope.firebaseURL + "todos/"));
    $scope.$firRef.$bind($scope, "todos").then(function(unbind) {
      $scope.unbindFunctionUnused = unbind;
    });
    
指令中的链接功能:

            var intervalId = $interval(function() {
                var squared = scope.item.counter * scope.item.counter;
                element.find(".squared").html(squared);
                scope.item.counter++;
            }, 1000);
        var intervalId = $interval(function() {

            var added = new Date(scope.item.dateAdded).getTime();
            var now = new Date().getTime();
            var diff = new Date(now - added);

            element.find(".timeelapsed").html(diff.toString());
        }, 1000);
起初我认为它与Date对象有关,但类似的奇怪行为也发生在整数上。(见下文)

2.填充一个数字的平方对于本地数组来说可以。对于与Firebase同步的阵列,不显示任何值(它偶尔闪烁)。
  • 基本代码如下

    $scope.firebaseURL = "https://flickering-counter.firebaseio-demo.com/";
    $scope.todosFirebase = [
        {name: 'plunker firebase', counter : 11, state: 1 },
        {name: 'github firebase', counter: 22, state: 2},
        {name: 'stack overflow firebase', counter: 33, state: 3}
    ];
    $scope.todos = [
        {name: 'plunker', counter : 11, state: 1 },
        {name: 'github', counter: 22, state: 2},
        {name: 'stack overflow', counter: 33, state: 3}
    ];
    $scope.state = 1;
    
    $scope.$firRef = $firebase(new Firebase($scope.firebaseURL + "todos/"));
    $scope.$firRef.$bind($scope, "todosFirebase").then(function(unbind) {
      $scope.unbindFunctionUnused = unbind;
    });
    
    $scope.addItem = function() { // note that we add to both instances
        $scope.todosFirebase.$add({name: $scope.newItem, state: $scope.state, counter: 0});
        $scope.todos.push({name: $scope.newItem, state: $scope.state, counter: 0});
    }
    
    指令中的链接功能:

                var intervalId = $interval(function() {
                    var squared = scope.item.counter * scope.item.counter;
                    element.find(".squared").html(squared);
                    scope.item.counter++;
                }, 1000);
    
            var intervalId = $interval(function() {
    
                var added = new Date(scope.item.dateAdded).getTime();
                var now = new Date().getTime();
                var diff = new Date(now - added);
    
                element.find(".timeelapsed").html(diff.toString());
            }, 1000);
    

昨天我问了相关的问题——它还涉及Firebase、Angular和3路数据绑定。今天我想进一步调查,但我有点被卡住了

我想做的是:

  • 我在列表中添加了一项
  • 它有一个柜台
  • 它每1秒刷新一次
  • 它只是工作
(由于某些原因,我无法使其在我的设置中工作)

实际上,我想在这个问题上投自己的一票:]

解决方案非常简单:

var _updateFunction = function() {
    var squared = scope.item.counter * scope.item.counter;
    element.find(".squared").html(squared); 
    scope.item.counter++;
}

var intervalId = $interval(_updateFunction, 1000);

_updateFunction(); // <-- cpt Obvious
var\u updateFunction=function(){
var平方=scope.item.counter*scope.item.counter;
元素.find(“.squared”).html(squared);
scope.item.counter++;
}
var intervalId=$interval(\u updateFunction,1000);
_updateFunction()//