如何从mongodb查询中获取对象并在同一个控制器中使用它?目前我无法从中获取对象属性。例如,我的对象有一个月,下面是一个代码示例:
budgetsApp.controller('BudgetsCostbreakdownController', function($scope, $stateParams, $http, $location,$modal,$log, Authentication, Budgets) {
// Get current budget
$scope.budget = Budgets.get({
budgetId: $stateParams.budgetId
});
$scope.chartObject.options = {
'title': 'My Budget and Expenses for month of'+$scope.budget.budgetMonth //wont appear in my view .
};
//end chart
}
);
答案 0 :(得分:0)
假设您的代码中某处定义了Budgets
对象等于$resource,您需要“等待”,直到数据从RESTful后端到达。
// Get current budget
Budgets.get({
budgetId: $stateParams.budgetId
}).$promise.then(function(result){
$scope.chartObject.options = {
'title': 'My Budget and Expenses for month of' + result.budgetMonth
};
});
答案 1 :(得分:0)
为此目的使用回调Resource.action([parameters], [success], [error])
// Get current budget
Budgets.get({budgetId: $stateParams.budgetId}, function(response) {
$scope.chartObject.options = {
'title': 'My Budget and Expenses for month of'+ response.budgetMonth //wont appear in my view .
};
});