2015-02-07 105 views
0

我建立一個頁面,它將從火力地堡動態檢索數據,並利用角路由服務於動態鏈接。AngularFire動態鏈接組件不工作

JS:

.controller("IdeaCtrl", ['$scope', '$firebase', '$routeParams', function($scope, $firebase, $routeParams) { 

    $scope.idea = { 
    ID: $routeParams.id 
    }; 

var ref = new Firebase("https://crowdfluttr.firebaseio.com/ideas/" + $scope.idea.ID); 
ref.on("value", function(snapshot) { 
    console.log(snapshot.val()); 
    var entries = snapshot.val(); 

    $scope.ideaTitle = entries.ideaTitle; 

    console.log($scope.ideaTitle); 

}, function (errorObject) { 
    console.log("The read failed: " + errorObject.code); 
}); 


}]) 

HTML:

ID: {{ idea.ID }} <br> 
    Title: {{ ideaTitle }} 

的{{idea.ID}}工作,但{{ideaTitle}}不露面。然而,兩個console.log都很好。什麼似乎是這個問題?

+1

Manube的答案應該工作。或者,把這個賦值放在'$ timeout'中。請閱讀https://www.firebase.com/docs/web/libraries/angular/guide.html#section-beyond-angularfire – 2015-02-07 22:22:25

+1

但是,爲什麼不使用AngularFire? '$ scope.idea = $ firebase(ref)。$ asObject()'然後'Title:{{idea.ideaTitle}}'應該是所需要的。這是記錄在這裏:https://www.firebase.com/docs/web/libraries/angular/guide.html#section-objects – 2015-02-07 22:26:40

+0

你的標題說AngularFire,但這裏沒有利用AngularFire。此外,您還沒有閱讀Firebase + Angular [涵蓋這些概念]的指南(https://www.firebase.com/docs/web/libraries/angular/guide.html#section-beyond-angularfire)不需要AngularFire的用戶。此外,這已[問]之前(http://stackoverflow.com/questions/21922470/how-come-angular-doesnt-update-with-scope-here/21923026#21923026)。 – Kato 2015-02-09 17:50:13

回答

3

請問

$scope.$apply() 

$scope.ideaTitle = entries.ideaTitle 

工作,通過任何機會呢?