IPEmailBuilderUiService
IPEmailBuilderUiService provides UI utilities for ngx-email-builder, with methods to manage settings and drop lists for columns/structures. It uses CdkPortal
and CdkPortalOutlet
and has an observable for the current settings portal.
Properties
columnsDropLists
: A set of drop lists for columns in the email builder UI.structuresDropLists
: A set of drop lists for structures in the email builder UI.currentSettingsPortal
$
: An observable for the currently attached settings portal.
Methods
attachSettingsPortal(portal: IPEmailBuilderSettingsDirective | null): void:
Attaches a settings portal to the email builder UI.
Parameters:portal
: The settings portal to attach.
setDefaultSettingsPortal(portal: IPEmailBuilderSettingsDirective): void:
Sets the default settings portal for the email builder UI.
Parameters:portal
: The default settings portal to set.
setSettingsPortalOutlet(portalOutlet: CdkPortalOutlet): void:
Sets the settings portal outlet for the email builder UI.
Parameters:portalOutlet
: The settings portal outlet to set.
- portalOutletHasAttached(): boolean: Checks if the settings portal outlet has attached.
Returns: true
if the outlet has attached, false
otherwise.
Usage
Here’s an example of how you might use the IPEmailBuilderUiService:
- Import the IPEmailBuilderUiService and inject it into your component or service using Angular’s dependency injection mechanism.
- Inside your component, define the necessary HTML templates for your settings portal and settings portal outlet. The template should include the
ng-template
tag with a reference variablesettingsPortal
to hold the content of the settings portal. ThecdkPortalOutlet
directive is used to dynamically render the current settings portal inside the<ng-container>
. - Implement the
OnInit
interface in your component and define the necessary logic inside thengOnInit
lifecycle hook. - Inside the
ngOnInit
method, perform the following tasks using the IPEmailBuilderUiService:
- Attach the settings portal by passing a
CdkPortal
instance created from thesettingsPortal
DOM element using theattachSettingsPortal()
method of the IPEmailBuilderUiService. - Set the default settings portal by passing a
CdkPortal
instance created from thedefaultSettingsPortal
DOM element using thesetDefaultSettingsPortal()
method of the IPEmailBuilderUiService. - Set the settings portal outlet by passing a
CdkPortalOutlet
instance created from thesettingsPortalOutlet
DOM element using thesetSettingsPortalOutlet()
method of the IPEmailBuilderUiService.
You can also use the IPEmailBuilderUiService in other parts of your application. Here are some actions you can perform using its methods:
- Attach a settings portal by passing your settings portal instance to the
attachSettingsPortal()
method. - Set the default settings portal by passing your default settings portal instance to the
setDefaultSettingsPortal()
method. - Set the settings portal outlet by passing your settings portal outlet instance to the
setSettingsPortalOutlet()
method. - Check if the settings portal outlet has been attached by calling the
portalOutletHasAttached()
method. This method returns a boolean value indicating whether the portal outlet has an attached portal. - Subscribe to the
currentSettingsPortal$
observable to get the currently attached settings portal. Inside the subscription, you can add your custom logic to handle the settings portal as needed. Remember to unsubscribe from the observable when you’re done using it to prevent memory leaks.
By following these steps, you can effectively use the IPEmailBuilderUiService in your Angular application to manage the settings portal and settings portal outlet for the email builder.
{% hint style=“info” %}
Note: There are two concrete implementations of the IPEmailBuilderUiService
: ProIPEmailBuilderUiService
the Pro version and FreeIPEmailBuilderUiService
for the Free version.
The appropriate implementation will be provided automatically based on your configuration. {% endhint %}