I am currently attempting to switch my service from using a hard coded static array to an array retrieved from a $http call. Despite my efforts, the implementation is not functioning as expected.
It is worth noting that the data returned from the http request is accurate and valid (I have omitted the link for privacy reasons).
Although I am not encountering any error messages, I am unable to provide additional information at this time. My main concern is whether I am approaching this problem in the correct manner.
I find myself frustrated by the complexity of what should be a simple task...
Here is the code for the hard-coded array:
.factory('Cards', function($http){
var cardTypes = [
{id: 1, USECASE_NAME: "Frank", USECASE_IMAGE: 'img/Frank.png', USECASE_DESC:"This is frank the bank card, He helps people all over the world make millions of transactions each year!", done: true },
{id: 2, USECASE_NAME: "John Lewis", USECASE_IMAGE: 'img/JohnLewis.png', USECASE_DESC:"John Lewis is one of the biggest retailers in the United Kingdom with a very proud reputation", done: true },
{id: 3, USECASE_NAME: "Generali", USECASE_IMAGE: 'img/Generali.png', USECASE_DESC:"Generali is the largest insurance company in Italy and arguably one of the biggest in Europe", done: true },
];
return {
all: function() {
return cardTypes;
}
}
});
And here is the code for the $http callback:
.factory('Cards', function($http) {
var cardTypes = {};
$http.post("http://url", {
"auth": "cats",
"name": "Adam",
"uuid": "fasfA"
}).
success(function(data, status, headers, config) {
cardTypes = data;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
return {
all: function() {
return cardTypes;
}
}
});