我遇到使用angularjs从Unsplash API获取随机图像的问题。我尝试使用我找到的以下代码示例,但它不起作用:
$scope.images = function() {
$http({
method: "GET",
header: {
'Content-Type': "application/json",
},
url: "https://unsplash.it/list",
}).then(function(res) {
var totalFound = res.data;
var photos = [];
for (var i = 0; i < totalFound; i++) {
var full = res.data[i].authors;
var regular = res.data[i].filename;
var thumb = res.data[i].posturl;
photos.push({
full: full,
regular: regular,
thumb: thumb
});
}
$scope.photos = photos;
console.log(totalFound);
},
function(res) {
console.log('error', res);
});
}
$scope.images();
如果我尝试console.log(photos.tumb),我会得到未定义的