試圖讓選定的點擊圖像在圖像庫中展開。我有擴展的工作,但它只適用於集合中的第一個圖像。如果我點擊集中的另一個圖像上的第一個是被擴大試圖讓圖像庫中的圖像在點擊上展開
<div ng-repeat="album in albumData|filter:q" id="thumbWrapper">
<h1>{{album.id}}</h1>
<h2 ng-click="showme = !showme">{{album.title}}</h2>
<div id="thumbList"ng-show="showme"class="albumContent">
<ul ng-controller="PhotoCtrl" id="thumbList">
<li ng-repeat="photo in photoData" ng-if="album.userId == photo.albumId">
<img id="view" ng-click="zoom()" ng-src={{photo.url}}>
</li>
</ul>
</div>
</div>
</div>
的一個,這裏是我的角度js代碼
var app = angular.module('myApp', []);
app.controller('AlbumCtrl', function ($scope, $http) {
$http.get("http://jsonplaceholder.typicode.com/albums").then(function(response) {
$scope.albumData = response.data;
console.log($scope.albumData);
});
});
app.controller('PhotoCtrl', function($scope, $http) {
$http.get("http://jsonplaceholder.typicode.com/photos").then(function(response) {
$scope.photoData = response.data;
$scope.zoom = function() {
var imageId = document.getElementById('view');
if(imageId.style.width == "1000px"){
imageId.style.width = "600px";
imageId.style.height = "600px";
}else{
imageId.style.width = "1000px";
imageId.style.height = "1000px";
}
};
// console.log($scope.photoData);
});
});
任何幫助將是真棒!
喜即時得到這個錯誤時,點擊觸發使用此代碼後:的ReferenceError:指數(eval at compile(angular.min.js:239),:4:210) at e(angular.min.js)沒有被定義爲 at f。$ scope.zoom(album.js:15) at fn :284) at b。$ eval(angular.min.js:148) at b。$ apply(angular.min.js:149) at HTMLImageElement。 (angular.min.js:284) at hg(angular.min.js:39) at HTMLImageElement.d(angular.min.js:39) –
Zohranio
您是否將index參數傳遞給函數中的html和js –
是的我在我的html:和js:$ scope.zoom = function(){ var elem =「view」+ index; var imageId = document.getElementById('elem'); if(imageId.style.width ==「1000px」){ imageId.style.width =「600px」; imageId.style.height =「600px」; } else { imageId.style.width =「1000px」; } }; – Zohranio