There have been many similar questions on stack overflow, but using the tips from this have not helped.
I am learning angular.js and am experimenting with $http.get on an API, but am experiencing issues while assigning the response to a variable.
the below get request is run on load. (this is my app.js file)
var app = angular.module('store',[]);
app.controller("StoreController", function($scope,$http){
var request = $http.get('/test').then(function (response) {
$scope.data = response;
return response;
});
request.then(function (data) {
this.products = $scope.data
});
});
The below is the response from the request (I can see this in the console view of the browser, but the data is not being displayed.)
[
{
name: 'Dowayne',
surname: 'Breedt',
catchphrase: 'wallawallabingbangamIright?',
reviews: [
{
stars: 5,
body: 'i love stuff',
soldOut: false,
},
{
stars: 4,
body: 'meh',
soldOut: true,
},
{
stars: 3,
body: 'shittake mushrooms',
soldOut: false,
},
]
}
];
This is all junk data (just for practice) but I can't for the life of me understand why it won't display on the HTML page, if I assign the above snippet directly to this.products, then it works perfectly/
What am I missing?
Thank you.