我正在使用Angular和Firebase。我想从函数Datasnapshot
获取值到$scope.getData
,但为什么我不能?请告诉我。谢谢。
$scope.$on('$routeChangeSuccess', function () {
var firebaseUrl ="https://angular-af216.firebaseio.com";
var commentRef = new Firebase(firebaseUrl).child('User');
commentRef.on('value', function(Datasnapshot) {
var comments = Datasnapshot.val();
// var data = Datasnapshot.child('User').val();
console.log(comments);
console.log("Newline");
$scope.getData = comments;
console.log(getData);
});
});
答案 0 :(得分:1)
在函数
中注入$scope
$scope.$on('$routeChangeSuccess', function ($scope) {
var firebaseUrl ="https://angular-af216.firebaseio.com";
var commentRef = new Firebase(firebaseUrl).child('User');
commentRef.on('value', function(Datasnapshot) {
var comments = Datasnapshot.val();
// var data = Datasnapshot.child('User').val();
console.log(comments);
console.log("Newline");
$scope.getData = comments;
console.log($scope.getData);
});
});