我试图传递一个Ng-重复我的$mdDialog,但没有找到多少关于如何这样做的文档。我一直指的是这堆,但在将图像传递给模式方面没有运气。
在控制台中,我收到一个错误:
TypeError: Cannot read property 'element' of undefined控制台错误和没有将图像传递给模态的原因是什么?
<md-grid-tile
ng-repeat="image in imageBucket.images"
md-rowspan="{{image.row}}"
md-rowspan-gt-lg="{{image.rowgtlg}}"
md-colspan="{{image.col}}"
md-colspan-gt-lg="{{image.colgtlg}}"
class="white" >
<md-button
class=""
ng-click="showAdvanced($event, image)"
flex="100"
flex-gt-md="auto">
<img
aria-label="kpinsonstairs"
class="img-responsive md-whiteframe-6dp"
src="{{image.src}}"
alt="Gallery Picture">
<md-grid-tile-footer>
<h3>{{image.title}}</h3>
</md-grid-tile-footer>
</md-button>
</md-grid-tile>Javascript
(function () {
'use strict';
angular
.module('resonance.gallery.controllers')
.controller('GalleryOneController', GalleryOneController);
GalleryOneController.$inject = [
'$scope',
'$mdDialog',
'ImageService'
];
function GalleryOneController($scope, $mdDialog, ImageService) {
ImageService.success(function(data) {
$scope.imageBucket = data;
});
$scope.showAdvanced = function(ev, image) {
$mdDialog.show({
clickOutsideToClose:true,
controller: function($mdDialog) {
var vm = this;
var image = {};
var image = image;
$scope.hide = function() {
$mdDialog.hide();
}
$scope.cancel = function() {
$mdDialog.cancel();
};
},
controllerAs: 'modal',
templateUrl: 'client/gallery/views/dialog.ng.html',
parent: angular.element(document.body),
targetEvent: ev
});
};
}
})();模式
<img
class="img-responsive md-whiteframe-6dp"
src="{{modal.image.src}}"
alt="Gallery Picture">发布于 2016-03-02 06:17:27
如果您查看角质材料的文档,您将看到有一个选项可以使用locals关键字将内容解析给模型的控制器。因此,您必须将该函数重写为:
$scope.showAdvanced = function(ev, image) {
$mdDialog.show({
clickOutsideToClose: true,
controller: function($mdDialog, image) {
var vm = this;
vm.image = image;
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
},
controllerAs: 'modal',
templateUrl: 'client/gallery/views/dialog.ng.html',
parent: angular.element(document.body),
targetEvent: ev,
locals: {
image: image
}
});
};那应该管用。
https://stackoverflow.com/questions/35679514
复制相似问题