【发布时间】:2015-01-08 09:52:51
【问题描述】:
我在 then() 中返回了一些数据,我需要将这些数据存储在“this”变量中。由于它没有存储在范围内,并且由于它被包装在回调中,因此我的控制器的“this”无效。如何备份数据以便将其存储在“this”中?见下文:
angular.module('logisticsApp.controllers').
controller('InventoryCtrl', ['$scope', '$http', '$window', 'DataService',
function ($scope, $http, $window, DataService) {
this.inventory = ''; // need to have data stored here
$scope.$on('$viewContentLoaded', angular.bind(this, function() {
// "this" is still valid here
myService.getInventory().then(function(data) {
// "this" is no longer valid!
$scope.inventory = data; // so this fails
});
}));
}]);
【问题讨论】:
标签: angularjs scope angularjs-scope promise