Toolbar items in Angular AI AssistView component
12 Dec 202524 minutes to read
You can render the AI AssistView toolbar items by using the items property in the toolbarSettings, responseToolbarSettings, promptToolbarSettings & footerToolbarSettings properties.
Configure footer toolbar
By default, the footer toolbar renders the send, if attachment is enabled the attachment item will also be rendered which allows users to send the prompt text or attach files as needed.
In the following example, AI AssistView component rendered with footer toolbar items such as send and attachment icons.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, ViewChild } from '@angular/core';
import { AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent [enableAttachments]="enableAttachments" (promptRequest)="onPromptRequest()" ></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
public enableAttachments: boolean = true;
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Toolbar positioning
You can use the toolbarPosition property to customize footer toolbar position. It has two modes such as Inline, and Bottom. By default, the toolbarPosition is Inline.
By settings toolbarPosition as Bottom, footer items will be rendered at the bottom with a dedicated footer area .
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, FooterToolbarSettingsModel, ToolbarItemClickedEventArgs } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<button id="toolbarBtn" class="e-btn" (click)="UpdateToolbarPosition()">UpdateToolbarPosition</button>
<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [footerToolbarSettings]="footerToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public footerToolbarSettings: FooterToolbarSettingsModel = {
toolbarPosition: 'Bottom'
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
public UpdateToolbarPosition = () => {
if (this.aiAssistViewComponent.footerToolbarSettings.toolbarPosition === 'Inline') {
this.aiAssistViewComponent.footerToolbarSettings.toolbarPosition = 'Bottom';
}
else {
this.aiAssistViewComponent.footerToolbarSettings.toolbarPosition = 'Inline';
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Adding custom items
You can use the footerToolbarSettings property to add custom items for the footer toolbar in the AI AssistView. The custom items will be added with the existing built-in items in the footer toolbar.
To know more about the items, please refer to the items section.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, FooterToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [footerToolbarSettings]="footerToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public footerToolbarSettings: FooterToolbarSettingsModel = {
toolbarPosition: 'Bottom',
items: [{iconCss: 'e-icons e-assistview-icon', align: 'Left'}]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Item click
The itemClick event is triggered when the footer toolbar item is clicked.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, FooterToolbarSettingsModel, ToolbarItemClickedEventArgs } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [footerToolbarSettings]="footerToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public footerToolbarSettings: FooterToolbarSettingsModel = {
itemClick: function (args: ToolbarItemClickedEventArgs) {
// Your required action here
}
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Adding header toolbar items
Items
The AI AssistView toolbar’s can be rendered by defining an array of items. Items can be constructed with the following built-in command types or item template.
Adding iconCss
You can customize the toolbar icons by using the iconCss property.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { iconCss: 'e-icons e-refresh', align: 'Right' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting item type
You can change the toolbar item type by using the type property. The type supports three types of items such as Button, Separator and Input. By default, the type is Button.
In the following example, toolbar item type is set as Button.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { iconCss: 'e-icons e-refresh', align: 'Right' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting text
You can use the text property to set the text for toolbar item.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { text: 'Welcome User !', align: 'Right' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Show or hide toolbar item
You can use the visible property to specify whether to show or hide the toolbar item. By default, its value is true.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [
{ type: 'Button', iconCss: 'e-icons e-refresh', align: 'Right', visible: false },
{ type: 'Button', iconCss: 'e-icons e-user', align: 'Right' }
]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting disabled
You can use the disabled property to disable the toolbar item. By default, its value is false.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [
{ type: 'Button', iconCss: 'e-icons e-refresh', align: 'Right', disabled: true },
{ type: 'Button', iconCss: 'e-icons e-user', align: 'Right' }
]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting tooltip text
You can use the tooltip property to specify the tooltip text to be displayed on hovering the toolbar item.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { type: 'Button', iconCss: 'e-icons e-refresh', align: 'Right', tooltip: 'Refresh' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting cssClass
You can use the cssClass property to customize the toolbar item.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { type: 'Button', iconCss: 'e-icons e-user', align: 'Right', cssClass: 'custom-btn' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting alignment
You can change the alignment of toolbar item by using the align property. It supports three types of alignments such as Left, Center and Right. By default, the value is Left.
In the following example, toolbar item type is set with Right.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { iconCss: 'e-icons e-refresh', align: 'Right' } ]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Enabling tab key navigation in toolbar
You can use the tabIndex property of a Toolbar item to enable tab key navigation for the item. By default, the user can switch between items using the arrow keys, but the tabIndex property allows you to switch between items using the Tab and Shift+Tab keys as well.
To use the tabIndex property, set it for each Toolbar item which you want to enable tab key navigation. The tabIndex property should be set to a positive integer value. A value of 0 or a negative value will disable tab key navigation for the item.
For example, to enable tab key navigation for two Toolbar items you can use the following code:
import { Component, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptRequestEventArgs, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [
{ text: "Item 1", tabIndex: 1 },
{ text: "Item 2", tabIndex: 2 }
]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}With the above code, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, in addition to using the arrow keys. The items will be navigated in the order specified by the tabIndex values.
If you set the tabIndex value to 0 for all Toolbar items, tab key navigation will be based on the element order rather than the tabIndex values. For example:
import { Component, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptRequestEventArgs, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [
{ text: "Item 1", tabIndex: 0 },
{ text: "Item 2", tabIndex: 0 }
]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}In this case, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, and the items will be navigated in the order in which they appear in the DOM.
Setting template
You can use the template property to add custom toolbar item in the AI AssistView.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { DropDownButton } from '@syncfusion/ej2-angular-splitbuttons';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()" [toolbarSettings]="toolbarSettings" (created)="created()"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [
{
type: 'Input', align: 'Right',
template: '<button id="ddMenu"></button>'
}
]
};
public created = () => {
var dropdown: DropDownButton = new DropDownButton({
items: this.dropdownItems,
content: 'English'
}, '#ddMenu');
};
public dropdownItems = [
{
text: 'हिंदी'
},
{
text: 'தமிழ்'
},
{
text: 'తెలుగు'
}
];
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Item clicked
The itemClicked event is triggered when the header toolbar item is clicked.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ToolbarSettingsModel, ToolbarItemClickedEventArgs } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [toolbarSettings]="toolbarSettings"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public toolbarSettings: ToolbarSettingsModel = {
items: [ { type: 'Button', iconCss: 'e-icons e-refresh', align: 'Right' } ],
itemClicked: function (args: ToolbarItemClickedEventArgs) {
// Your required action here
}
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Built-in toolbar items
Prompt
By default, the prompt toolbar renders the built-in items such as edit and copy items. These allow users to edit the prompt text or copy as needed.
In the following example, AI AssistView component rendered with built-in toolbar items such as edit and copy items.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { PromptModel, AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData: PromptModel[] = [
{
prompt: "Can you help me create a summary of the latest trends in AI technology?",
response: `<div>Sure! Here are the latest trends in AI technology:
<ul>
<li><strong>Generative AI:</strong> Improved models like GPT-4 enhance natural language processing.</li>
<li><strong>AI in Healthcare:</strong> AI aids in diagnostics and personalized treatments.</li>
<li><strong>Autonomous Systems:</strong> Self-driving cars and drones are advancing.</li>
<li><strong>AI Ethics:</strong> Focus on bias, privacy, and accountability in AI.</li>
<li><strong>Edge AI:</strong> Processing moves to local devices, boosting IoT.</li>
</ul>
</div>`
}
];
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting width
You can use the width property to set the width of the prompt toolbar in the AI AssistView.
Item clicked
The itemClicked event is triggered when the prompt toolbar item is clicked.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptToolbarSettingsModel, ToolbarItemClickedEventArgs } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [promptToolbarSettings]="promptToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public promptToolbarSettings: PromptToolbarSettingsModel = {
itemClicked: function (args: ToolbarItemClickedEventArgs) {
// Your required action here
}
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Response
By default, the response toolbar renders the built-in items like copy, like, and dislike items to perform response copy and perform rating actions.
In the following example, AI AssistView renders with built-in toolbar items.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { PromptModel, AIAssistViewComponent } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest()" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData: PromptModel[] = [
{
prompt: "Can you help me create a summary of the latest trends in AI technology?",
response: `<div>Sure! Here are the latest trends in AI technology:
<ul>
<li><strong>Generative AI:</strong> Improved models like GPT-4 enhance natural language processing.</li>
<li><strong>AI in Healthcare:</strong> AI aids in diagnostics and personalized treatments.</li>
<li><strong>Autonomous Systems:</strong> Self-driving cars and drones are advancing.</li>
<li><strong>AI Ethics:</strong> Focus on bias, privacy, and accountability in AI.</li>
<li><strong>Edge AI:</strong> Processing moves to local devices, boosting IoT.</li>
</ul>
</div>`
}
];
public onPromptRequest = () => {
setTimeout(() => {
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting width
You can use the width property to set the width of the response toolbar in the AI AssistView.
Item clicked
The itemClicked event is triggered when the response toolbar item is clicked.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ResponseToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [responseToolbarSettings]="responseToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
public responseToolbarSettings: ResponseToolbarSettingsModel = {
items: [
{ type: 'Button', iconCss: 'e-icons e-download' },
{ type: 'Button', iconCss: 'e-icons e-refresh' },
{ type: 'Button', iconCss: 'e-icons e-assist-like' },
{ type: 'Button', iconCss: 'e-icons e-assist-dislike' },
]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Adding custom toolbar items
You can also add custom toolbar items in the AI AssistView by using the toolbarSettings, responseToolbarSettings & promptToolbarSettings properties.
Prompt
You can use the promptToolbarSettings property to add custom items for the prompt toolbar in the AI AssistView.
To know more about the items, please refer to the
itemssection.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [promptToolbarSettings]="promptToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public promptToolbarSettings: PromptToolbarSettingsModel = {
items: [
{ type: 'Button', iconCss: 'e-icons e-edit' }
]
};
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Response
You can use the responseToolbarSettings property to add custom response toolbar in the AI AssistView.
To know more about the items, please refer to the
itemssection.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AIAssistViewModule } from '@syncfusion/ej2-angular-interactive-chat';
import { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, ResponseToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
import { PromptRequestEventArgs } from '@syncfusion/ej2-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, AIAssistViewModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the AI AssistView component
template: `<div ejs-aiassistview #aiAssistViewComponent (promptRequest)="onPromptRequest($event)" [responseToolbarSettings]="responseToolbarSettings" [prompts]="promptsData"></div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
public onPromptRequest = (args: PromptRequestEventArgs) => {
setTimeout(() => {
let foundPrompt = this.promptsData.find((promptObj: any) => promptObj.prompt === args.prompt);
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
this.aiAssistViewComponent.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
};
public responseToolbarSettings: ResponseToolbarSettingsModel = {
items: [
{ type: 'Button', iconCss: 'e-icons e-download' },
{ type: 'Button', iconCss: 'e-icons e-refresh' },
{ type: 'Button', iconCss: 'e-icons e-assist-like' },
{ type: 'Button', iconCss: 'e-icons e-assist-dislike' },
]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Item clicked
The itemClicked event is triggered when the custom toolbar item is clicked.