我在运行中定义了一个$ 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时,我可以展开对象并查看用户对象!!!
但第二个console.log是未定义的。请帮忙!
答案 0 :(得分:0)
您是否注入了$ firebase模块?
function myCtrl($rootScope, $scope, $firebase) {
...
};