Skip to content

Commit

Permalink
enable optional controller and templates for modal (IdanCo#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
selvach committed Sep 1, 2017
1 parent ae2813c commit 1f9e82f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/library/modal/modal.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const DEFAULT_OPTIONS = {
};

class ModalService {
constructor ($document, $compile, $rootScope, $q) {
constructor ($document, $compile, $rootScope, $q, $controller) {
this.$document = $document;
this.$compile = $compile;
this.$rootScope = $rootScope;
this.$q = $q;
this.$controller = $controller;
}

openPrompt(options) {
Expand All @@ -29,7 +30,7 @@ class ModalService {
// new scope for the modal
const modalScope = this.$rootScope.$new(true);
// prepare the modal element
const modalElement = angular.element(template);
const modalElement = angular.element(options.template || template);
// get the document body
const body = this.$document.find('body').eq(0);

Expand All @@ -44,6 +45,14 @@ class ModalService {
// open the modal
modalElement.modal();

// instantiate an optional controller
if (options.controller) {
this.$controller(options.controller, {$scope: modalScope, $element: modalElement});
}

// add promise to modalScope
modalScope.deferred = deferred;

// handle button click
modalScope.closeModal = (button) => {
modalElement.modal('hide');
Expand Down

0 comments on commit 1f9e82f

Please sign in to comment.