[英]Angular Factory returning index.html as response.data instead of JSON
I'm lost on this one. 我迷失了这个。
I've set up a productFactory that is meant to $http.get
hardcoded JSON data. 我已经建立了一个productFactory,该产品旨在用于
$http.get
硬编码的JSON数据。 This JSON has been validated by JSONlint. 此JSON已通过JSONlint验证。
Instead of returning this data, the data returned is my index.html file. 而不是返回此数据,返回的数据是我的index.html文件。 What could be causing this?
是什么原因造成的?
productFactory: 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. 记录到控制台的响应是我整个index.html文件的字符串版本。
Is /public/
actually a part of the path to the file? /public/
实际上是文件路径的一部分吗? 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. 尝试在浏览器中查看
product.json
并确保Angular在同一路径上调用GET
。
你试过这个吗?
angular.fromJson(response);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.