2014-01-09 2 views
0

$ bind에서 반환 된 약속을 사용하여 데이터가 firebase에서 되돌아 오면 작업을 수행하려고합니다. 그러나 $ bind를 사용하여 대부분의 시간 약속을 만들 때 firebase에서 데이터가 반환되기 전에 "then"함수가 실행됩니다.

여러 $ binds는 데이터가 firebase에서 돌아온 후 첫 번째 "then"만 실행하지만, 객체에 바인딩하지 않은 경우에만 해당됩니다.

firebase에있는 오브젝트의 $ bind에서 실행되는 "then"은 데이터가 사용 가능 해지면 결코 돌아 오지 않는 것처럼 보입니다.

angular.module('myApp', ['firebase']) 
    .controller('HomeCtrl', ['$scope', '$rootScope', '$firebase', 
    function($scope, $rootScope, $firebase) { 


    // Data 1 
    // The first bind's then will fire correctly 
    $scope.data1 = $firebase(new Firebase("https://bindTest.firebaseio.com/users/1/email")); 
    $scope.data1.$bind($scope, "data1Remote").then(function() { 
    console.log("data1Remote: then"); 
    console.log($scope.data1Remote); 
    $scope.data1RemoteThen = angular.copy($scope.data1Remote); 
    }); 
    console.log("data1Remote: not then"); 
    console.log($scope.data1Remote); 


    // Data 2 
    // The then function doesn't seem to work at all if it references an object 
    $scope.data2 = $firebase(new Firebase("https://bindTest.firebaseio.com/users/1")); 
    $scope.data2.$bind($scope, "data2Remote").then(function() { 
    console.log("data2Remote: then"); 
    console.log($scope.data2Remote); 
    $scope.data2RemoteThen = angular.copy($scope.data2Remote); 
    }); 
    console.log("data1Remote: not then"); 
    console.log($scope.data1Remote); 


    // Data 3 
    // Since this section follows another bind the then doesn't work. 
    $scope.data3 = $firebase(new Firebase("https://bindTest.firebaseio.com/syncedValue")); 
    $scope.data3.$bind($scope, "data3Remote").then(function() { 
    console.log("data3Remote: then"); 
    console.log($scope.data3Remote); 
    $scope.data3RemoteThen = angular.copy($scope.data3Remote); 
    }); 
    console.log("data2Remote: not then"); 
    console.log($scope.data1Remote); 

} 
    ]); 

"then"함수는 firebase가 데이터를 범위에 바인딩 한 후에 만 ​​실행해야합니다. 나는이 문제를 설명하는 Plunker를 만들었습니다. 서로 다른 조합으로 다른 데이터 섹션을 주석 처리하면 올바르게 반환되는 "다음"이 변경됩니다. 다른 누구도이 문제에 대한 경험이 있거나 해결책을 찾았습니까? 감사.

http://plnkr.co/edit/9UgDxx?p=preview

답변

0

이것이 버그이었다 밝혀졌습니다. 나는 그것을보고했고 Anant는 그것을 아주 빨리 고쳤다. 굉장해. 이 수정은 angularFire github의 master 브랜치에 적용됩니다.

+0

수정 프로그램은 AngularFire v0.6.0과 함께 출시 될 예정입니다. 신고 해 주셔서 감사합니다! – Anant

관련 문제