Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created May 5, 2017 18:13
Show Gist options
  • Save Ibro/12a9b1444f2401aa4d3a87f3fc23342a to your computer and use it in GitHub Desktop.
Save Ibro/12a9b1444f2401aa4d3a87f3fc23342a to your computer and use it in GitHub Desktop.
RxJS Socket.IO Angular Chat - Angular Service - Coding Blast - www.codingblast.com
import { Component } from '@angular/core';
import { ChatService } from '../chat.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
message: string;
messages: string[] = [];
constructor(private chatService: ChatService) {
}
sendMessage() {
this.chatService.sendMessage(this.message);
this.message = '';
}
ngOnInit() {
this.chatService
.getMessages()
.subscribe((message: string) => {
this.messages.push(message);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment