试图让选定的点击图像在图像库中展开。我有扩展的工作,但它只适用于集合中的第一个图像。如果我点击集中的另一个图像上的第一个是被扩大试图让图像库中的图像在点击上展开
<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