So in my angularJS program, I'm trying to retrieve data from the database and I do so successfully but then lose the value of my variable. Why is this and how can I fix this?
function loadLocOptions() {
locTaskOptionsReq.requestLocTaskOptions(vm.task).then(function (data) {
if (data == null) {
vm.locOptions = locTaskOptionsService.getEmptylocTaskOption();
vm.locOptions.ERPKey = sessionService.getCurrentUser().ERPKey;
vm.locOptions.LocKey = sessionService.getCurrentUser().LocKey;
} else {
vm.locOptions = data;
}
vm.locOptionsLoaded = true;
// Data is here
console.log(vm.locOptions);
});
// Now is null
console.log(vm.locOptions);
}
i'm trying to then call use my locOptions
to use my html:
<div ng-repeat="loc in vm.locOptions">...</div>
here's my controller that as well:
module.component("asaLocOptionsComponent", {
bindings: { task: '='},
controllerAs: "vm",
controller: ["$scope", "$location", "shellPageAdapter", "sessionService", "staticData", "activeData", "ScreenModes", "localizationService", "locationReq", "locTaskOptionsService", "locTaskOptionsReq", asaLocOptionsController],
transclude: false,
templateUrl: "/system/SystemManager/app/organization/asaLocOptions.html"
});