,我嘗試讀取一個JSON文件(即在同一目錄作爲我的HTML頁面),但每當我運行的應用程序是我有這個問題表明this.(This is my html page - code behind)
。 JSON文件 -JSON文件不顯示數據
[
{ "_id":"1", "description":"Samsung Note 4", "price":899, "image": "samsung-note4.png", "platform":"Android Jellybean" },
{ "_id":"2", "description":"iPhone 6", "price":1028, "image": "iphone6.png", "platform":"iOS 8" },
{"_id": "3","description": "HTC One (M8)","price": 768,"image": "htc-one.png","platform": "Windows 8"}
]
這是我的JS文件 -
App.controller('ProductController', function($scope, $http){
$http.get('products.json')
.then(function(res){
$scope.products = res.data;
});
$scope.selectProduct = function (id) {
$scope.product = _.where($scope.products, {_id: id})[0];
}
});
我不知道爲什麼我無法獲取jSON文件中的數據。任何可能的原因?
您可以檢查控制檯中的網絡選項卡並告訴我什麼是AJAX請求的響應?它可以幫助檢測問題。使用chrome開發工具 – murli2308
當你的$ http.get方法運行後,console.log(res)會得到什麼? –