我想讀一下包含的歌曲列表和URL的圖像麻煩在angularJs
{"songs" : [
{
"SongName" : "Broken Dreams",
"image" : "img/browser.svg"
},
{
"SongName" : "My heart goes on",
"image" : "img/browser.svg"
},
{
"SongName" : "Summer of 69",
"image" : "img/browser.svg"
},
{
"SongName" : "Broken Hearted Girl",
"image" : "img/browser.svg"
},
{
"SongName" : "American idiot",
"image" : "img/browser.svg"
}
]}
但基本的問題是,當我使用$ http.get一個JSON文件中讀取JSON數據(),它讀取JSON,但我不能把它分配給了angularJS對象,這裏是我的angularJS代碼
var app = angular.module('TheSlideShow', []);
app.controller('mainController', ['$scope', '$http', function($scope, $http){
$scope.test = "this is a test string";
$scope.songList = {};
$http.get("Data/SongList.json", ['$scope']).success(function(List){ $scope.songList = List.songs; console.log("The Length : " + $scope.songList.length);});
for(var i = 0; i< $scope.length; i++)
{
console.log("loop number" + i);
}
}]);
長度字段給出結果爲5,但我的for循環不會爲一個連運行單次..
你有聯繫的quesion是基於jquery,我正在尋找angularJS方式! –