src/modal/modal.service.ts
Extends Base Modal Service to create Alert Modal with a function call. Placed in a seperate service
to prevent remote scoping (NG3003) which has side effects. Hence, import cycles are not allowed when
compilationMode is set to partial.
Modal service handles instantiating and destroying modal instances. Uses PlaceholderService to track open instances, and for it's placeholder view reference.
Properties |
|
Methods |
constructor(placeholderService: PlaceholderService)
|
||||||
|
Defined in src/modal/modal.service.ts:17
|
||||||
|
Creates an instance of
Parameters :
|
| show | ||||||||
show(data: AlertModalData)
|
||||||||
|
Defined in src/modal/modal.service.ts:42
|
||||||||
|
Creates and renders a new alert modal component.
Parameters :
Returns :
any
|
| create | ||||||
create(data: literal type)
|
||||||
|
Inherited from
BaseModalService
|
||||||
|
Defined in
BaseModalService:47
|
||||||
Type parameters :
|
||||||
|
Creates and renders the modal component that is passed in.
Parameters :
Returns :
ComponentRef<any>
|
| destroy | ||||||
destroy(index)
|
||||||
|
Inherited from
BaseModalService
|
||||||
|
Defined in
BaseModalService:95
|
||||||
|
Destroys the modal on the supplied index. When called without parameters it destroys the most recently created/top most modal.
Parameters :
Returns :
void
|
| Public placeholderService |
Type : PlaceholderService
|
|
Inherited from
BaseModalService
|
|
Defined in
BaseModalService:21
|
| Protected environment |
Type : EnvironmentInjector
|
Default value : inject(EnvironmentInjector)
|
|
Inherited from
BaseModalService
|
|
Defined in
BaseModalService:36
|
|
Current module/component injection enviornment Allows modules to use providers from calling component Root Module/ └── Lazy loaded Feature Module/ ├── Provides Service & imports modules ├── Modal component (component that extends base component) └── Modal component launcher (dynamically creates modal component) Passing EnvironmentInjector in |
| Protected Static modalList |
Type : Array<ComponentRef<any>>
|
Default value : []
|
|
Inherited from
BaseModalService
|
|
Defined in
BaseModalService:19
|
import { Injectable, ViewContainerRef } from "@angular/core";
import { AlertModal } from "./alert-modal.component";
import { AlertModalData } from "./alert-modal.interface";
import { PlaceholderService } from "carbon-components-angular/placeholder";
import { BaseModalService } from "./base-modal.service";
/**
* Extends Base Modal Service to create Alert Modal with a function call. Placed in a seperate service
* to prevent remote scoping (NG3003) which has side effects. Hence, import cycles are not allowed when
* compilationMode is set to `partial`.
*
*
* Modal service handles instantiating and destroying modal instances.
* Uses PlaceholderService to track open instances, and for it's placeholder view reference.
*/
@Injectable()
export class ModalService extends BaseModalService {
/**
* Creates an instance of `ModalService`.
*/
constructor(public placeholderService: PlaceholderService) {
super(placeholderService);
}
/**
* Creates and renders a new alert modal component.
* @param data You can pass in:
* `type` - "default" | "danger" = "default",
* `label` - a label shown over the title,
* `title` - modal's title,
* `content` - modal's content, could include HTML tags.
* `buttons` is an array of objects
* `close` custom close function
* ```
* {
* text: "Button text",
* type: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger--primary" = "primary",
* click: clickFunction,
* }
* ```
*/
show(data: AlertModalData) {
return this.create({
component: AlertModal,
inputs: {
type: data.type,
label: data.label,
title: data.title,
content: data.content,
hasScrollingContent: data.hasScrollingContent !== undefined ? data.hasScrollingContent : null,
size: data.size,
buttons: data.buttons || [],
close: data.close || (() => { }),
showCloseButton: data.showCloseButton
}
});
}
}