0.1.1 • Published 6 months 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-library
Import and configuration
- Add
ChatLibraryModule
toimports
insrc/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
ChatLibraryService
andIUsersConfig
toimports
insrc/app/app.component.ts
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 {}
Set basic properties
- Defined
usersConfig: IUsersConfig
- Defined
messages: Message[] = []
- Set
usersConfig
andmessages
inconstructor
- Defined
processMessage
function
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-library
tosrc/app/app.component.html
<sej-ngx-chat-library (messageSent)="processMessage($event)"></sej-ngx-chat-library>