DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Chat - Customization

Use the following properties to customize the DevExtreme Chat component:

Backend API
<div class="demo-container"> <div class="chat-container"> <dx-chat #chat [height]="710" [user]="currentUser" [items]="messages$ | async" [showAvatar]="true" [showUserName]="true" [showDayHeaders]="true" [showMessageTimestamp]="true" [dayHeaderFormat]="dayHeaderFormats[0]" [messageTimestampFormat]="messageTimestampFormats[0]" [disabled]="false" (onMessageEntered)="onMessageEntered($event)" > </dx-chat> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <dx-check-box text="Avatar" [(value)]="chat.showAvatar"></dx-check-box> </div> <div class="option"> <dx-check-box text="User Name" [(value)]="chat.showUserName" ></dx-check-box> </div> <div class="option-separator"></div> <div class="option"> <dx-check-box text="Day Headers" [(value)]="chat.showDayHeaders" ></dx-check-box> </div> <div class="option"> <span>Day Header Format:</span> <dx-select-box [items]="dayHeaderFormats" [(value)]="chat.dayHeaderFormat" [inputAttr]="dayHeaderLabel" ></dx-select-box> </div> <div class="option-separator"></div> <div class="option"> <dx-check-box text="Message Timestamp" [(value)]="chat.showMessageTimestamp" ></dx-check-box> </div> <div class="option"> <span>Message Timestamp Format:</span> <dx-select-box [items]="messageTimestampFormats" [(value)]="chat.messageTimestampFormat" [inputAttr]="messageTimestampLabel" ></dx-select-box> </div> <div class="option-separator"></div> <div class="option"> <dx-check-box text="Disable Chat" [(value)]="chat.disabled" ></dx-check-box> </div> </div> </div>
import { bootstrapApplication } from '@angular/platform-browser'; import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import { AsyncPipe } from '@angular/common'; import { DxChatModule, DxCheckBoxModule, DxSelectBoxModule } from 'devextreme-angular'; import { DxChatTypes } from 'devextreme-angular/ui/chat'; import { Observable } from 'rxjs'; import { AppService } from './app.service'; if (!/localhost/.test(document.location.host)) { enableProdMode(); } @Component({ selector: 'demo-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], imports: [ DxChatModule, DxCheckBoxModule, DxSelectBoxModule, AsyncPipe, ], }) export class AppComponent { currentUser: DxChatTypes.User; supportAgent: DxChatTypes.User; messages$: Observable<DxChatTypes.Message[]>; dayHeaderFormats = this.appService.dayHeaderFormats; messageTimestampFormats = this.appService.messageTimestampFormats; dayHeaderLabel = this.appService.dayHeaderLabel; messageTimestampLabel = this.appService.messageTimestampLabel; constructor(private readonly appService: AppService) { [this.currentUser, this.supportAgent] = this.appService.getUsers(); this.messages$ = this.appService.messages$; } onMessageEntered(event: DxChatTypes.MessageEnteredEvent) { this.appService.onMessageEntered(event); } } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), AppService, ], });
.demo-container { min-width: 720px; display: flex; gap: 20px; } ::ng-deep .chat-container { display: flex; flex-grow: 1; align-items: center; justify-content: center; } ::ng-deep .options { padding: 20px; display: flex; flex-direction: column; min-width: 280px; background-color: rgba(191, 191, 191, 0.15); gap: 16px; } ::ng-deep .dx-chat { max-width: 480px; } ::ng-deep .caption { font-size: var(--dx-font-size-sm); font-weight: 500; } ::ng-deep .option-separator { border-bottom: 1px solid var(--dx-color-border); } ::ng-deep .dx-avatar { border: 1px solid var(--dx-color-border); }
import { Injectable } from '@angular/core'; import { Observable, BehaviorSubject } from 'rxjs'; import { DxChatTypes } from 'devextreme-angular/ui/chat'; @Injectable({ providedIn: 'root', }) export class AppService { date: Date; currentUser: DxChatTypes.User = { id: 'c94c0e76-fb49-4b9b-8f07-9f93ed93b4f3', name: 'John Doe', }; supportAgent: DxChatTypes.User = { id: 'd16d1a4c-5c67-4e20-b70e-2991c22747c3', name: 'Support Agent', avatarUrl: '../../../../images/petersmith.png', }; dayHeaderFormats = ['dd/MM/yyyy', 'dd.MM.yyyy', 'MMMM dd, yyyy', 'EEEE, MMMM dd']; messageTimestampFormats = ['hh:mm a', 'hh:mm:ss a', 'HH:mm', 'HH:mm:ss']; messageTimestampLabel = { 'aria-label': 'Message Timestamp Format' }; dayHeaderLabel = { 'aria-label': 'Day Header Format' }; messages: DxChatTypes.Message[] = []; messagesSubject: BehaviorSubject<DxChatTypes.Message[]> = new BehaviorSubject([]); constructor() { this.date = new Date(); this.date.setHours(0, 0, 0, 0); this.messages = [ { timestamp: this.getTimestamp(this.date, -9), author: this.supportAgent, text: 'Hello, John!\nHow can I assist you today?', }, { timestamp: this.getTimestamp(this.date, -7), author: this.currentUser, text: 'Hi, I\'m having trouble accessing my account.', }, { timestamp: this.getTimestamp(this.date, -7), author: this.currentUser, text: 'It says my password is incorrect.', }, { timestamp: this.getTimestamp(this.date, -7), author: this.supportAgent, text: 'I can help you with that. Can you please confirm your UserID for security purposes?', }, { timestamp: this.getTimestamp(this.date, 1), author: this.currentUser, text: 'john.doe1357', }, { timestamp: this.getTimestamp(this.date, 1), author: this.supportAgent, text: '✅ Instructions to restore access have been sent to the email address associated with your account.', }, ]; this.messagesSubject.next(this.messages); } get messages$(): Observable<DxChatTypes.Message[]> { return this.messagesSubject.asObservable(); } getUsers(): DxChatTypes.User[] { return [this.currentUser, this.supportAgent]; } getTimestamp(date: Date, offsetMinutes = 0): number { return date.getTime() + offsetMinutes * 60000; } onMessageEntered(event: DxChatTypes.MessageEnteredEvent) { this.messages = [...this.messages, event.message]; this.messagesSubject.next(this.messages); } }
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> <script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script> <script src="./bundle.js" type="module"></script> </body> </html>