Custom views in Angular AI AssistView component
27 Aug 202515 minutes to read
The AI AssistView component supports multiple views that allow you to organize different types of content within the same component.
Adding custom views
The e-views selector enables you to define a collection of different view models within the AI AssistView component. Each view can be independently customized with different appearances and content.
Setting view type
You can specify the type of view using the type property within the e-view selector. It accepts two values such as Assist, and Custom.
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, PromptRequestEventArgs } 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)">
<e-views>
<e-view type="Assist"></e-view>
<e-view type="Custom"></e-view>
</e-views>
</div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
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 name
You can use the name property to specifies the header name of the Assist or Custom views 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 { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptRequestEventArgs } 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)">
<e-views>
<e-view name="Prompt"></e-view>
<e-view name="Response"></e-view>
</e-views>
</div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
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 iconCss
You can customize the view icons using the iconCss property. By default the e-assistview-icon class is added as built-in header icon for 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 { Component, HostListener, ViewChild } from '@angular/core';
import { AIAssistViewComponent, PromptRequestEventArgs } 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)">
<e-views>
<e-view iconCss="e-icons e-assistview-icon"></e-view>
<e-view type="Custom" iconCss="e-icons e-comment-show"></e-view>
</e-views>
</div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
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));The following example illustrates how types, name, and iconCss are used in a AI AssistView component.
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 } 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)">
<e-views>
<e-view type="Assist" name="Prompt" iconCss="e-icons e-assistview-icon"></e-view>
<e-view type="Custom" name="Response" iconCss="e-icons e-comment-show" [viewTemplate]="viewTemplate">
<ng-template #viewTemplate>
<div class="view-container"><h5>Response view content</h5></div>
</ng-template>
</e-view>
</e-views>
</div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
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 view template
The viewTemplate property allows to define custom content for multiple views within 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 { Component, HostListener, 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>
<e-views>
<e-view type="Assist" name="Prompt" [viewTemplate]="viewTemplate">
<ng-template #viewTemplate>
<div class="view-container"><h5>Prompt view content</h5></div>
</ng-template>
</e-view>
<e-view type="Custom" name="Response" [viewTemplate]="viewTemplate">
<ng-template #viewTemplate>
<div class="view-container"><h5>Response view content</h5></div>
</ng-template>
</e-view>
</e-views>
</div>`
})
export class AppComponent {
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting activeView
You can use the activeView property to specify which view should be displayed when the AI AssistView component initializes. By default, the first view (index 0) is set as active.
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 } 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)" [activeView]="activeView">
<e-views>
<e-view type="Assist" name="Prompt"></e-view>
<e-view type="Custom" name="Response" iconCss="e-icons e-comment-show" [viewTemplate]="viewTemplate">
<ng-template #viewTemplate>
<div class="view-container"><h5>Response view content</h5></div>
</ng-template>
</e-view>
</e-views>
</div>`
})
export class AppComponent {
@ViewChild('aiAssistViewComponent')
public aiAssistViewComponent!: AIAssistViewComponent;
public activeView: number = 1;
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));