5

私は $rootscope オブジェクトを実行で定義しています..

//Start the AngularJS App
var angularApp = angular.module('angularApp')

//Run at the start of the Angular Application
.run(function ($rootScope, $location, $firebase, $firebaseSimpleLogin) {

    //Create the User Object. 
    $rootScope.user = $firebase($rootScope.fb.child('/persons/person1'));

   //this works fine!
    console.log($rootScope.user.userId)

});

$rootScope.user は、userId、userName、userEmail などを保持します...

後で、コントローラーで $rootScope.user のデータを使用したいのですが、未定義です!

function myCtrl($rootScope, $scope) {

    //need to use $rootsope.user.userId in this command...
    $scope.folders = $firebase($rootScope.fb.child('/persons/' + $rootScope.user.userId);

    //this will display the $rootScope in the console no problem!
    console.log($rootScope);

   //this just displays 'undefined'
   console.log($rootScope.user);

};

私を狂わせているのは、myCtrl が Chrome JavaScript コンソールに $rootScope を表示すると、オブジェクトを展開してユーザー オブジェクトを表示できることです!!!

しかし、2 番目の console.log は未定義です。助けてください!

4

1 に答える 1

0

$firebase モジュールを注入しましたか?

function myCtrl($rootScope, $scope, $firebase) {
   ...    
};
于 2014-12-29T17:41:54.860 に答える