"this"변수 안에 저장해야하는 then() 내에서 일부 데이터가 반환됩니다. 범위 내에 저장되지 않고 콜백 내부에 래핑되었으므로 컨트롤러의 "this"가 유효하지 않습니다. 데이터를 다시 버블 링하여 "this"안에 저장할 수 있습니까? 아래를 참조AngularJS에서 "컨트롤러로"구문과 "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
});
}));
}]);
[함수 내부의 별칭 컨트롤러에 변수를 할당하는 방법?] (HTTP의 가능한 중복 : //stackoverflow.com/questions/26822784/how-to-assign-variables-to-an-aliased-controller-inside-a-function) – zeroflagL