Closed fernandojsg closed 9 years ago
workaround with decorator
function LightboxController($scope) {
// own stuff
};
LightboxController.$inject = ['$scope'];
module.config(['$provide', function ($provide) {
$provide.decorator('lightboxSrcDirective', function ($delegate) {
var directive = $delegate[0];
directive.controller = LightboxController;
return $delegate;
});
}]);
You can also add your own controller to the lightbox itself. In lightbox.html
:
<div class="modal-body"
ng-swipe-left="Lightbox.nextImage()"
ng-swipe-right="Lightbox.prevImage()"
ng-controller="LightboxCtrl">
...
<button type="button"
btn-click="LightboxCtrl.myNewFunction(Lightbox.image)"
class="btn btn-danger">Do something</button>
...
</div>
And write the controller separately:
angular.module('app').controller('LightboxCtrl', function () {
$scope.myNewFunction = function (image) {
// Do something with image
};
});
I'll add a real example/demo to the docs.
Perfect! Thank you very much
I've took your starting example and tried to achive the following: Modify the
lightbox.html
to include a button to perform a custom action in the main controller.So far I've done the following:
And the part of the modified
lightbox.html
including the button is:But as fas as I understand, it's not possible to pass a controller to the lightbox, is it right? Is there any way to achieve it with the current implementation?