I am trying to use promises to tidy up my Angular code a bit. When I enter a callback function (success or error) however. My scope is gone. The $scope, service and object are all null inside the callback.
The variable vm is still known though.
Any ideas on how I can fix this?
(function (app) {
'use strict';
var MyController = (function () {
function MyController($scope, aService, anotherService) {
var vm = {
loaded: false,
anObjToInstantiate: null,
error: null
};
aService.makeAServiceCall()
.success(function (result) {
vm.anObjToInstantiate = result.data;
anotherService.notifySomething(); /* Null! */
vm.loaded = true;
})
.error(_handleError);
function _handleError(error) {
vm.error = error;
}
return vm;
};
MyController.$inject = ['$scope', 'AService', 'AnotherService'];
return MyController;
}());
app.controller('MyController', MyController);
}(angular.module('app.amodule')));