【发布时间】:2015-03-21 15:31:21
【问题描述】:
.controller('FrameCtrl', ['$scope','$state','$rootScope', '$stateParams',
function($scope, $state, $rootScope, $stateParams) {
console.log($rootScope); // all the data is there.
console.log($rootScope.activeAddress); // undefined
console.log($rootScope.activeRestaurant); // undefined
}])
我试图理解为什么,即使 $rootScope 对象同时包含 activeAddress 和 activeRestaurant 对象,当我专门 console.log() 它们时它们是空的。
在之前状态的控制器中,我使用这两行代码设置了这两个对象,如果有区别的话:
// Parse.com promise returns array of addresses after login.
$rootScope.activeAddress = data.addresses[0];
// After getting restaurant ID from activeAddress, copy object to activeRestaurant
$rootScope.activeRestaurant = $rootScope.aRestaurant;
简而言之,我想知道为什么 $rootScope.activeAddress 和 $rootScope.activeRestaurant 返回 undefined,即使它们出现在 $rootScope 父对象中。
编辑: 以下是之前状态的 HTML 页面的标记:
<button class="button button-block button-positive" ng-click="login()"
ui-sref="frame.menu({menu: 'appetizers'})">
LOG IN
</button>
【问题讨论】:
-
我注意到,当您使用
console.log输出某些内容时,对象似乎具有在调用console.log之后设置的属性。尝试克隆@rootScope并输出克隆,您会看到它没有这些属性。例如:stackoverflow.com/questions/22146684/… -
你如何改变状态..??
-
@squiroid 我添加了 HTML
-
尝试使用
$timeout(function(){console.log($rootScope.activeAddress); console.log($rootScope.activeRestaurant);})打印它们
标签: angularjs controller parse-platform ionic-framework