I'm lost on this one.
I've set up a productFactory that is meant to $http.get
hardcoded JSON data. This JSON has been validated by JSONlint.
Instead of returning this data, the data returned is my index.html file. What could be causing this?
productFactory:
angular.module('APP').factory('productFactory', function($http) {
var productFactory = {
getProducts:function(){
return $http.get('/public/data/product.json')
.then(function(response) {
console.log(response);
return response;
});
},
}
return productFactory;
})
The response logged to the console is a string version of my entire index.html file.
Is /public/
actually a part of the path to the file? Usually the public folder is set up as the document root and doesn't actually appear in the path to any resource.
Try getting to view product.json
in a browser and make sure Angular is calling GET
on the same path.
你试过这个吗?
angular.fromJson(response);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.