dialog.service.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. var core_1 = require("@angular/core");
  16. var dialog_holder_component_1 = require("./dialog-holder.component");
  17. var DialogServiceConfig = (function () {
  18. function DialogServiceConfig() {
  19. this.container = null;
  20. }
  21. return DialogServiceConfig;
  22. }());
  23. exports.DialogServiceConfig = DialogServiceConfig;
  24. var DialogService = (function () {
  25. function DialogService(resolver, applicationRef, injector, config) {
  26. this.resolver = resolver;
  27. this.applicationRef = applicationRef;
  28. this.injector = injector;
  29. this.container = config && config.container;
  30. }
  31. DialogService.prototype.addDialog = function (component, data, options) {
  32. if (!this.dialogHolderComponent) {
  33. this.dialogHolderComponent = this.createDialogHolder();
  34. }
  35. return this.dialogHolderComponent.addDialog(component, data, options);
  36. };
  37. DialogService.prototype.removeDialog = function (component) {
  38. if (!this.dialogHolderComponent) {
  39. return;
  40. }
  41. this.dialogHolderComponent.removeDialog(component);
  42. };
  43. DialogService.prototype.removeAll = function () {
  44. this.dialogHolderComponent.clear();
  45. };
  46. DialogService.prototype.createDialogHolder = function () {
  47. var _this = this;
  48. var componentFactory = this.resolver.resolveComponentFactory(dialog_holder_component_1.DialogHolderComponent);
  49. var componentRef = componentFactory.create(this.injector);
  50. var componentRootNode = componentRef.hostView.rootNodes[0];
  51. if (!this.container) {
  52. var componentRootViewContainer = this.applicationRef['_rootComponents'][0];
  53. this.container = componentRootViewContainer.hostView.rootNodes[0];
  54. }
  55. this.applicationRef.attachView(componentRef.hostView);
  56. componentRef.onDestroy(function () {
  57. _this.applicationRef.detachView(componentRef.hostView);
  58. });
  59. this.container.appendChild(componentRootNode);
  60. return componentRef.instance;
  61. };
  62. return DialogService;
  63. }());
  64. DialogService = __decorate([
  65. core_1.Injectable(),
  66. __param(3, core_1.Optional()),
  67. __metadata("design:paramtypes", [core_1.ComponentFactoryResolver, core_1.ApplicationRef, core_1.Injector, DialogServiceConfig])
  68. ], DialogService);
  69. exports.DialogService = DialogService;
  70. //# sourceMappingURL=dialog.service.js.map