Customization in Angular Predefined dialogs component
27 Apr 202414 minutes to read
You can customize the predefined dialogs buttons by using below properties.
-
okButton
- Use this property to customize OK button text. -
cancelButton
- Use this property to customize Cancel button text.
Use the following code snippet for alert, confirm and prompt to customize the predefined dialogs action buttons.
For alert dialog , customized the default dialog button content as Dismiss
by using the text
property.
For confirm dialog, customized the default dialog buttons content as Yes
and No
by using the text
property and also customized the dialog button icons by using icon
property.
For prompt dialog , customized the default dialog buttons content as Connect
and Close
by using text
property.
Alert action button
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button cssClass="e-danger" #alertButton (click)="alertBtnClick()">Alert</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public alertBtnClick = (): void => {
DialogUtility.alert({
title: 'Low Battery',
content: '10% of battery remaining',
width : '250px',
okButton: { text: 'Dismiss'}
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Confirm action buttons
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button cssClass="e-success" #confirmButton (click)="confirmBtnClick()">Confirm</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public confirmBtnClick = (): void => {
DialogUtility.confirm({
title: 'Delete Multiple Items',
content: 'Are you sure you want to permanently delete these items?',
width:'300px',
okButton: { text: 'Yes', icon:'e-icons e-check'},
cancelButton: {text:'No', icon:'e-icons e-close'}
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Prompt action buttons
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button [isPrimary]="true" #promptButton (click)="promptBtnClick()">Prompt</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public promptBtnClick = (): void => {
DialogUtility.confirm({
title: 'Join Chat Group',
content:'<p>Enter your name:</p> <input id= "inputEle" type="text" name="Required" class="e-input" placeholder="Type here.." />',
width: '300px',
okButton: { text: 'Connect'},
cancelButton: {text:'Close'}
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Show or hide dialog close button
When rendering the predefined dialogs through utility methods, You can close the dialog using the following ways. The default values of closeOnEscape
and showCloseIcon
is false
.
- By pressing the escape key if the closeOnEscape property is enabled.
- By clicking the close button if the showCloseIcon property is enabled.
You can also manually close the Dialogs by creating an instance to the dialog and call the hide method.
Use the following code for alert, confirm and prompt to demonstrates the different ways of hiding the utility dialog.
Alert dialog close button
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button cssClass="e-danger" #alertButton (click)="alertBtnClick()">Alert</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public alertBtnClick = (): void => {
DialogUtility.alert({
title: 'Low Battery',
content: '10% of battery remaining',
width : '250px',
showCloseIcon : true,
closeOnEscape : true
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Confirm dialog close button
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button cssClass="e-success" #confirmButton (click)="confirmBtnClick()">Confirm</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public confirmBtnClick = (): void => {
DialogUtility.confirm({
title: 'Delete Multiple Items',
content: 'Are you sure you want to permanently delete these items?',
width:'300px',
showCloseIcon : true,
closeOnEscape : true
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Prompt dialog close button
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button [isPrimary]="true" #promptButton (click)="promptBtnClick()">Prompt</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public promptBtnClick = (): void => {
DialogUtility.confirm({
title: 'Join Chat Group',
content:
'<p>Enter your name:</p> <input id= "inputEle" type="text" name="Required" class="e-input" placeholder="Type here.." />',
width: '300px',
showCloseIcon : true,
closeOnEscape : true
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customize dialog content
You can load custom content in predefined dialogs using the content
property.
Use the following code to customize the dialog content to render the custom TextBox component inside the prompt dialog to get the username from the user.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DialogModule } from '@syncfusion/ej2-angular-popups'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DialogUtility } from '@syncfusion/ej2-popups';
@Component({
imports: [
DialogModule,
ButtonModule
],
standalone: true,
selector: 'app-root',
template: `<button ejs-button [isPrimary]="true" #promptButton (click)="promptBtnClick()">Prompt</button>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
throw new Error('Method not implemented.');
}
public promptBtnClick = (): void => {
DialogUtility.confirm({
title: 'Join Chat Group',
content: '<p>Enter your name:</p><input class="e-input" placeholder="Type here.." />',
width: '300px'
});
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));