在控制器未定义$ rootscope价值 [英] $rootscope value undefined in Controller
本文介绍了在控制器未定义$ rootscope价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在运行中定义,像这样一个$ rootscope对象。
I have a $rootscope object defined in the run like so..
//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持有用户id,用户名,USEREMAIL,等等...
$rootScope.user holds userId, userName, userEmail, etc...
后来,在控制器,我想用在$ rootScope.user但其不确定的一些数据!
Later, in a controller, I want to use some data in $rootScope.user but its undefined!
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显示$ rootScope铬的JavaScript控制台,我可以扩大对象,并看到用户对象!
What is driving me insane is that when myCtrl displays the $rootScope in chrome javascript console, I can expand the object and SEE the user object!!!
但第二的console.log仅仅是不确定的。请大家帮忙!
But the second console.log is just undefined. please help!
推荐答案
你注入$火力模块?
function myCtrl($rootScope, $scope, $firebase) {
...
};
这篇关于在控制器未定义$ rootscope价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文