OK so Im trying to create a Factory that will make a call to my REST api to retrieve data. All was fine until I updated to Angular 1.6 which forced me to use Promises and so I decided to try factories out:
var registerApplication = angular.module('applications', ['ajoslin.promise-tracker']);
registerApplication.factory('HTTPFactory', ['$http', function dataService($http) {
var applications = {};
applications = function getApplications() { $http ({
'url': '/adminapi/getApplications',
'method': 'GET',
'cache' : true
}).then(function(response){
// return response.data;
console.log(response);
return response;
});
}
return applications;
}]);
registerApplication.controller("ApplicationController", ['HTTPFactory', function ($scope, HTTPFactory) {
$scope.applications = {};
getApplications();
// when landing on the page, get all applications and show them
function getApplications() {
HTTPFactory.getApplications().then(function(response){
$scope.applications = response;
});
}
}]);
However I'm getting this error: angular.js:10859Error: undefined is not an object (evaluating 'HTTPFactory.getApplications')
I've tried several ways and all seem to give me an error of some form, what am I doing wrong???