我想从JSON文件中读取图像,然后返回未定义的内容,但不确定是否丢失。我对此很陌生。我正在使用AngularJS。我尝试使用console.log检查变量,但似乎变量无法捕获值。
HTML
<body ng-app="myApp" ng-controller="myCtrl">
<div class="banner">
<ul id="lightSlider" >
<li ng-repeat="image in images"><img ng-src="{{image.img}}">
</li>
</ul>
</div>
</body>
JS
var app = angular.module('myApp', []);
app.controller('myCtrl',["$scope","$http", "$timeout"
,function($scope, $http, $timeout) {
$http({
method: 'GET',
url: 'imageSlider.json'
}).then(function successCallback(data){
$scope.images = data.items;
console.log(data.items);
}, function errorCallback(response){
alert("something went wrong!")
});
$timeout(function(){
$("#lightSlider").lightSlider({
item:1,
auto: true,
loop:true,
speed:1000,
pause:3000,
});
},0)
}]);