繁体   English   中英

如何在$ on事件处理程序中使用$ scope

[英]How can I use $scope in $on event handler

我正在使用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);
    });             
});      

在函数中注入$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);
        });

      }); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM