File

src/modal/modal.service.ts

Description

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.

Extends

BaseModalService

Index

Properties
Methods

Constructor

constructor(placeholderService: PlaceholderService)

Creates an instance of ModalService.

Parameters :
Name Type Optional
placeholderService PlaceholderService No

Methods

show
show(data: AlertModalData)

Creates and renders a new alert modal component. 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

Example :
{
        text: "Button text",
        type: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger--primary" = "primary",
        click: clickFunction,
}
Parameters :
Name Type Optional Description
data AlertModalData No

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

Example :
{
text: "Button text",
type: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger--primary" = "primary",
click: clickFunction,
}
Returns : any
create
create(data: literal type)
Inherited from BaseModalService
Type parameters :
  • T

Creates and renders the modal component that is passed in. inputs is an optional parameter of data that can be passed to the Modal component.

Parameters :
Name Type Optional
data literal type No
Returns : ComponentRef<any>
destroy
destroy(index)
Inherited from BaseModalService

Destroys the modal on the supplied index. When called without parameters it destroys the most recently created/top most modal.

Parameters :
Name Optional Default value
index No -1
Returns : void

Properties

Public placeholderService
Type : PlaceholderService
Inherited from BaseModalService
Protected environment
Type : EnvironmentInjector
Default value : inject(EnvironmentInjector)
Inherited from BaseModalService

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 createComponent will look for provider declaration in feature module instead of root module. This is required to pass correct context in a lazy-loaded applications. Services injected in root, will also be available as feature module enviornment will also hierarchically inherit the root services.

Protected Static modalList
Type : Array<ComponentRef<any>>
Default value : []
Inherited from BaseModalService
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
			}
		});
	}
}

results matching ""

    No results matching ""