我在运行中定义了一个 $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 只是未定义。请帮忙!
你注入了 $firebase 模块吗?
function myCtrl($rootScope, $scope, $firebase) {
...
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)