1

Here is my http service code:

app.controller('StoreController', ['$http', function($http){
    var store = this;
    store.products = [];
    $http.get('/store-products.json').then(function(data){
        store.products = data;
    });
}]);

And here is my JSON code:

[
    {
        "name": "...",
        "price": 20.00,
        "description": "...",
        "canPurchase": false,
        "images": [
            "...jpg",
            "...jpg",
            "...jpg"
        ],
        "reviews": []
    },
    {
        "name": "...",
        "price": 15.95,
        "description": "...",
        "canPurchase": true,
        "images": [],
        "reviews": []
    }
]

When I run the code on localhost server, it does not show my objects. There is also no errors in the console that show so I cannot see where I am going wrong. Can anyone see the issue here?

1 Answer 1

1

your json data is wrapped at response.data of $http.get.

change to below code will solve the problem(also make sure your json file is at right location).

$http.get('/store-products.json').then(function(res){
    store.products = res.data;
});

Plunker demo.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked! Thank you. I'm learning angular at the moment and the way I coded the http service first is the way they advised to code it strangely..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.