我尝试开发一个Image-Viewer。我希望能够添加多个画廊来包含图像,并且应该有可能“复制”一个画廊。那就是我现在停留的地方。
我可以添加新的画廊,但不能重复一个。复制时,图库会在我的数组中复制,但看不到。此后添加新画廊时,它们也不会显示。
我一点都不明白。
一些代码:
// Controller for binding galleries to view
app.controller('newMainCtrl', function($scope, ImageGalleriesService) {
$scope.galleries = ImageGalleriesService.getGalleries();
$scope.$watch(function(){
return ImageGalleriesService.getGalleries();
}, function(newVal){
$scope.galleries = newVal;
});
});
// Single Image controller
app.controller('imageCtrl', function($scope, ImageGalleriesService) {
$scope.imageinit = function(value)
{
$scope.imageitem = value;
};
});
// Gallery controller
app.controller('galleryCtrl', function($scope, ImageGalleriesService) {
$scope.init = function(gallery) {
$scope.gallery = gallery;
};
$scope.duplicate = function()
{
ImageGalleriesService.addImageGallery($scope.gallery, null, 2);
};
});
// Service that holds all the galleries
app.service('ImageGalleriesService', function() {
var imagegalleries = [];
this.getGalleries = function(){
return imagegalleries;
};
this.addImageGallery = function(imagegallery){
imagegalleries.push(imagegallery);
};
});
我弄了个笨拙的东西来显示问题。
任何帮助表示赞赏,谢谢!
使用track by $index
在你的HTMLng-repeat="gallery_ in galleries track by $index"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句