Skip to content

Instantly share code, notes, and snippets.

@adhamankar
Created January 18, 2016 12:18
Show Gist options
  • Save adhamankar/66eeb3a1216385286fb8 to your computer and use it in GitHub Desktop.
Save adhamankar/66eeb3a1216385286fb8 to your computer and use it in GitHub Desktop.
Angular- ModalService - wrapper on top of $modal service
/// <reference path="../../_references.ts" />
module Common.Services {
"use strict";
export class ModalService implements Common.Framework.IModalContainer {
public static $inject = ["$modal"];
public static Factory($modal: ng.ui.bootstrap.IModalService) {
return new ModalService($modal);
}
private dismissCallback: (reason: any) => any;
public modalInstance: ng.ui.bootstrap.IModalServiceInstance;
constructor(public $modal: ng.ui.bootstrap.IModalService) {
}
public openModal = (settings: ng.ui.bootstrap.IModalSettings, onClosingModal?: (reason: any) => any
, onDismissingModal?: (reason: any) => any) => {
if (this.modalInstance) {
//throw new Error("Trying to open a dialog that is already open!");
return;
}
this.dismissCallback = onDismissingModal;
this.modalInstance = this.$modal.open(settings);
this.modalInstance.result.then(onClosingModal, this.dismissModal);
};
public dismissModal = () => {
this.modalInstance = null;
if (this.dismissCallback !== null && this.dismissCallback !== undefined) {
this.dismissCallback("dismissed");
}
};
public closeModal = (success) => {
if (this.modalInstance) {
this.modalInstance.close(success);
}
this.modalInstance = null;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment