-4
通過點擊鏈接顯示照片顯示陣列的最後一個圖像。 控制器:AngularJS通過點擊
app.controller('ExampleController', function(PhotoService, $scope) {
var vm = this;
vm.showImg = false;
vm.load = function(event) {
vm.showImg = !vm.showImg;
if ($scope.link)
return;
PhotoService.getPhoto(event.rid)
.then(function success(response) {
response.data.forEach(function (element, index) {
$scope.link = '/load/img/'+ response.data[index].filename;
});
});
};
})
.service("PhotoService", function($http, $q) {
this.getPhoto = function(rid) {
return $http.get('http://portal.com/device/record/' + rid);
};
});
查看:
<a href="" ng-click="ShowImg = !ShowImg;vm.load(event)">Show images</a>
<img ng-show="ShowImg" ng-src="// link //" alt="фото"/>
如何通過點擊打開的圖像上進行,而不是將其顯示在數組中以下。