Skip to content

Instantly share code, notes, and snippets.

@KerryRitter
Created July 7, 2016 15:10
Show Gist options
  • Save KerryRitter/6607b1429fe8abccf6d31d252c649f54 to your computer and use it in GitHub Desktop.
Save KerryRitter/6607b1429fe8abccf6d31d252c649f54 to your computer and use it in GitHub Desktop.
ComponentModalService
export class ComponentModalService {
public static $inject = ["$uibModal"];
private _modalInstance: ng.ui.bootstrap.IModalServiceInstance;
public constructor(
private _modalService: ng.ui.bootstrap.IModalService
) {
}
public open(component: ng.IComponentOptions, resolve: any): ng.IPromise<any> {
const options: ng.ui.bootstrap.IModalSettings = {
controller: component.controller,
controllerAs: "$ctrl",
backdrop: "static",
size: "lg",
resolve: resolve
};
if (!_.isEmptyOrWhiteSpace(component.template)) {
if (_.isString(component.template)) {
options.template = component.template as string;
} else {
options.template = (component.template as Function)();
}
}
if (!_.isEmptyOrWhiteSpace(component.templateUrl)) {
if (_.isString(component.template)) {
options.templateUrl = component.templateUrl as string;
} else {
options.templateUrl = component.templateUrl as () => string;
}
}
this._modalInstance = this._modalService.open(options);
return this._modalInstance.result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment