我正在尝试将组件的方法deletePhoto
和editPhoto
方法公开businessPhotos
到verticalGrid
组件中。但是有些是无法访问的。
任何帮助将不胜感激,谢谢
照片.js
angular.module('business')
.component('businessPhotos', {
templateUrl: 'business/photos.html',
controller: [ function() {
var $ctrl = this;
$ctrl.editPhoto = function(photo) {
// code
};
$ctrl.deletePhoto = function(id) {
// code
};
}]
});
照片.html
<vertical-grid ng-if="$ctrl.business.provider_photos" cells="$ctrl.business.provider_photos" delete-photo="$ctrl.deletePhoto(id)" edit-photo="$ctrl.editPhoto(photo)"></vertical-grid>
垂直网格.js
angular.module('dashboard')
.component('verticalGrid', {
bindings: {
cells: '<',
deletePhoto: '&',
editPhoto: '&'
},
templateUrl: 'utils/vertical-grid.html',
selector: 'vertical-grid',
controller: ['$element', function($element) {
var $ctrl = this;
$ctrl.colGrid = [];
var numOfCols = 4;
var numOfCells = $ctrl.cells.length;
$ctrl.colCssClass = 'col-xs-3';
for (var i = 0; i < numOfCells; i++) {
var colIndex = i % numOfCols;
if (!$ctrl.colGrid[colIndex]) {
$ctrl.colGrid[colIndex] = [];
}
$ctrl.colGrid[colIndex].push($ctrl.cells[i]);
}
}]
});
垂直网格.html
<div class="provider-photos row">
<div class="{{$ctrl.colCssClass}}" ng-repeat="col in $ctrl.colGrid track by $index">
<div class="photo-outer-tile" ng-repeat="cell in col track by $index">
<div class="photo-tile">
<img ng-src="{{cell.tile_url}}">
<div class="photo-controls">
<a ng-click="$ctrl.deletePhoto(cell.id)" href="javascript:void(0);">Delete</a>
<a href="javascript:void(0);">Crop</a>
</div>
</div>
</div>
</div>
</div>