|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Getting started with Angular Chat UI | Syncfusion |
| 4 | +description: Checkout and learn about Getting started with Angular Chat UI component of Syncfusion Essential JS 2 and more details. |
| 5 | +platform: ej2-angular |
| 6 | +control: Chat UI |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Getting started in Angular Chat UI component |
| 12 | + |
| 13 | +This section explains how to create a simple **Chat UI** component and configure its available functionalities in Angular. |
| 14 | + |
| 15 | +## Dependencies |
| 16 | + |
| 17 | +The following list of dependencies are required to use the Angular Chat UI component in your application. |
| 18 | + |
| 19 | +```javascript |
| 20 | +|-- @syncfusion/ej2-angular-interactive-chat |
| 21 | + |-- @syncfusion/ej2-angular-base |
| 22 | + |-- @syncfusion/ej2-base |
| 23 | + |-- @syncfusion/ej2-navigations |
| 24 | + |-- @syncfusion/ej2-inputs |
| 25 | + |-- @syncfusion/ej2-popups |
| 26 | + |-- @syncfusion/ej2-buttons |
| 27 | +``` |
| 28 | + |
| 29 | +## Setup angular environment |
| 30 | + |
| 31 | +Angular provides the easiest way to set angular CLI projects using [`Angular CLI`](https://github.com/angular/angular-cli) tool. |
| 32 | + |
| 33 | +Install the CLI application globally to your machine. |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install -g @angular/cli |
| 37 | +``` |
| 38 | + |
| 39 | +## Create a new application |
| 40 | + |
| 41 | +```bash |
| 42 | +ng new syncfusion-angular-chat-ui |
| 43 | +``` |
| 44 | + |
| 45 | +By default, it install the CSS style base application. To setup with SCSS, pass --style=scss argument on create project. |
| 46 | + |
| 47 | +Example code snippet. |
| 48 | + |
| 49 | +```bash |
| 50 | +ng new syncfusion-angular-chat-ui --style=scss |
| 51 | +``` |
| 52 | + |
| 53 | +Navigate to the created project folder. |
| 54 | + |
| 55 | +```bash |
| 56 | +cd syncfusion-angular-chat-ui |
| 57 | +``` |
| 58 | + |
| 59 | +## Installing Syncfusion Chat UI package |
| 60 | + |
| 61 | +Syncfusion packages are distributed in npm as `@syncfusion` scoped packages. You can get all the Angular Syncfusion package from npm [link]( https://www.npmjs.com/search?q=%40syncfusion%2Fej2-angular- ). |
| 62 | + |
| 63 | +Currently, Syncfusion provides two types of package structures for Angular components, |
| 64 | +1. Ivy library distribution package [format](https://v17.angular.io/guide/angular-package-format) |
| 65 | +2. Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package. |
| 66 | + |
| 67 | +### Ivy library distribution package |
| 68 | + |
| 69 | +Syncfusion Angular packages(`>=20.2.36`) has been moved to the Ivy distribution to support the Angular [Ivy](https://docs.angular.lat/guide/ivy) rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command. |
| 70 | + |
| 71 | +Add `@syncfusion/ej2-angular-interactive-chat` package to the application. |
| 72 | + |
| 73 | +```bash |
| 74 | +npm install @syncfusion/ej2-angular-interactive-chat --save |
| 75 | +``` |
| 76 | + |
| 77 | +### Angular compatibility compiled package(ngcc) |
| 78 | + |
| 79 | +For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion Angular components. To download the `ngcc` package use the below. |
| 80 | + |
| 81 | +Add `@syncfusion/ej2-angular-interactive-chat@ngcc` package to the application. |
| 82 | + |
| 83 | +```bash |
| 84 | +npm install @syncfusion/ej2-angular-interactive-chat@ngcc --save |
| 85 | +``` |
| 86 | + |
| 87 | +To mention the ngcc package in the `package.json` file, add the suffix `-ngcc` with the package version as below. |
| 88 | + |
| 89 | +```bash |
| 90 | +@syncfusion/ej2-angular-interactive-chat:"27.1.48-ngcc" |
| 91 | +``` |
| 92 | + |
| 93 | +>Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning. |
| 94 | +
|
| 95 | +## Registering Chat UI module |
| 96 | + |
| 97 | +Import Chat UI module into Angular application(app.module.ts) from the package `@syncfusion/ej2-angular-interactive-chat`. |
| 98 | + |
| 99 | +```javascript |
| 100 | +import { NgModule } from '@angular/core'; |
| 101 | +import { BrowserModule } from '@angular/platform-browser'; |
| 102 | +// import the ChatUIModule for the Chat UI component |
| 103 | +import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat'; |
| 104 | +import { AppComponent } from './app.component'; |
| 105 | + |
| 106 | +@NgModule({ |
| 107 | + //declaration of ej2-angular-interactive-chat module into NgModule |
| 108 | + imports: [ BrowserModule, ChatUIModule ], |
| 109 | + declarations: [ AppComponent ], |
| 110 | + bootstrap: [ AppComponent ] |
| 111 | +}) |
| 112 | +export class AppModule { } |
| 113 | +``` |
| 114 | + |
| 115 | +## Adding CSS reference |
| 116 | + |
| 117 | +The following CSS files are available in `../node_modules/@syncfusion` package folder. |
| 118 | +This can be referenced in [src/styles.css] using following code. |
| 119 | + |
| 120 | +```css |
| 121 | +@import "../node_modules/@syncfusion/ej2-base/styles/material.css"; |
| 122 | +@import '../node_modules/@syncfusion/ej2-interactive-chat/styles/material.css'; |
| 123 | +@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css'; |
| 124 | +@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css'; |
| 125 | +@import '../node_modules/@syncfusion/ej2-popups/styles/material.css'; |
| 126 | +@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css'; |
| 127 | +``` |
| 128 | + |
| 129 | +## Adding Chat UI component |
| 130 | + |
| 131 | +Modify the template in [src/app/app.component.ts] file to render the Angular Chat UI component. Add the Angular Chat UI by using `<ejs-chatui>` selector in `template` section of the app.component.ts file. |
| 132 | + |
| 133 | +```javascript |
| 134 | +import { Component } from '@angular/core'; |
| 135 | +import { ChatUIComponent } from '@syncfusion/ej2-angular-interactive-chat'; |
| 136 | + |
| 137 | +@Component({ |
| 138 | + selector: 'app-root', |
| 139 | + // specifies the template string for the Chat UI component |
| 140 | + template: `<div ejs-chatui id='chatUI'></div>` |
| 141 | +}) |
| 142 | +export class AppComponent { } |
| 143 | +``` |
| 144 | + |
| 145 | +## Run the application |
| 146 | + |
| 147 | +After completing the configuration required to render a basic Chat UI, run the following command to display the output in your default browser. |
| 148 | + |
| 149 | +``` |
| 150 | +ng serve |
| 151 | +``` |
| 152 | + |
| 153 | +The following example illustrates the output in your browser. |
| 154 | + |
| 155 | +{% tabs %} |
| 156 | +{% highlight ts tabtitle="app.component.ts" %} |
| 157 | +{% include code-snippet/chat-ui/getting-started/src/app.component.ts %} |
| 158 | +{% endhighlight %} |
| 159 | + |
| 160 | +{% highlight ts tabtitle="main.ts" %} |
| 161 | +{% include code-snippet/chat-ui/getting-started/src/main.ts %} |
| 162 | +{% endhighlight %} |
| 163 | +{% endtabs %} |
| 164 | + |
| 165 | +{% previewsample "page.domainurl/samples/chat-ui/getting-started" %} |
| 166 | + |
| 167 | +## Configure messages and user |
| 168 | + |
| 169 | +You can use the `messages` property to add messages and the `user` property to configure the current user for the chat. |
| 170 | + |
| 171 | +{% tabs %} |
| 172 | +{% highlight ts tabtitle="app.component.ts" %} |
| 173 | +{% include code-snippet/chat-ui/defaultmessages/src/app.component.ts %} |
| 174 | +{% endhighlight %} |
| 175 | + |
| 176 | +{% highlight ts tabtitle="main.ts" %} |
| 177 | +{% include code-snippet/chat-ui/defaultmessages/src/main.ts %} |
| 178 | +{% endhighlight %} |
| 179 | +{% endtabs %} |
| 180 | + |
| 181 | +{% previewsample "page.domainurl/samples/chat-ui/defaultmessages" %} |
0 commit comments