0.1.1 • Published 2 years ago
sej-ngx-chat-library v0.1.1
Chat Library
ChatLibrary es una biblioteca de Angular que proporciona un componente de chat.
Getting Started
Install
npm install --save sej-ngx-chat-libraryImport and configuration
- Add
ChatLibraryModuletoimportsinsrc/app/app.module.ts: Configure OPTIONS in
forRoot:import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { ChatLibraryModule } from 'sej-ngx-chat-library'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, ChatLibraryModule.forRoot({ showAvatarHeader: true, showAvatarMessage: true, showSeen: true, showSendTime: true, }), ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
- Add
Add
ChatLibraryServiceandIUsersConfigtoimportsinsrc/app/app.component.tsimport { Component } from '@angular/core'; import { ChatLibraryService } from 'sej-ngx-chat-library'; import { IUsersConfig } from 'sej-ngx-chat-library/lib/interfaces/users-config.interface'; import { Message } from 'sej-ngx-chat-library/lib/classes/message.class'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent {}Set basic properties
- Defined
usersConfig: IUsersConfig - Defined
messages: Message[] = [] - Set
usersConfigandmessagesinconstructor - Defined
processMessagefunction
import { Component } from '@angular/core'; import { ChatLibraryService } from 'sej-ngx-chat-library'; import { IUsersConfig } from 'sej-ngx-chat-library/lib/interfaces/users-config.interface'; import { Message } from 'sej-ngx-chat-library/lib/classes/message.class'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { usersConfig: IUsersConfig = { senderName: '', senderAvatar: '', senderSeen: new Date(), ownerName: '', ownerAvatar: '' } messages: Message[] = []; constructor(private chatLibraryService: ChatLibraryService) { this.chatLibraryService.messages = this.messages; this.chatLibraryService.usersConfig = this.user; } processMessage(message) { ... } }- Defined
Add
sej-ngx-chat-librarytosrc/app/app.component.html<sej-ngx-chat-library (messageSent)="processMessage($event)"></sej-ngx-chat-library>