File

src/app/chats/chats.component.ts

Implements

OnInit

Metadata

encapsulation ViewEncapsulation.None
selector app-chats
styleUrls ./chats.component.scss
templateUrl ./chats.component.html

Index

Properties
Methods

Constructor

constructor(service: ChatsService)
Parameters :
Name Type Optional
service ChatsService No

Methods

createChat
createChat()
Returns : void
getChatsList
getChatsList()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onActiveChat
onActiveChat(chat)
Parameters :
Name Optional
chat No
Returns : void
sendChat
sendChat(chat)
Parameters :
Name Optional
chat No
Returns : void

Properties

activeChat
Type : any
chatName
Type : string
Default value : 'demo'
chats
Type : any
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ChatsFirebase } from './chats.firebase';
import { ChatsService } from './chats.service';

@Component({
  selector: 'app-chats',
  templateUrl: './chats.component.html',
  styleUrls: ['./chats.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ChatsComponent implements OnInit {
  chats: any;
  activeChat: any;

  chatName: string = 'demo';

  constructor(private service: ChatsService) {}

  ngOnInit() {
    this.getChatsList();
  }

  getChatsList() {
    this.service.getChatsList().subscribe(chats => {
      this.chats = chats;
      this.activeChat = chats[0];
    });
  }

  createChat() {
    let d = {
      picture: 'assets/images/avatars/2.jpg',
      name: this.chatName,
      messages: [
        {
          message: '这是 Angular 2 交流群',
          when: 1,
          who: 'me'
        },
        {
          message: '推荐下Angular 2 有哪些开源项目?',
          when: 1,
          who: 'partner'
        }
      ],
      lastMessageTime: 1,
      lastMessage: '技术交流'
    };
    this.service.createChat(d);
  }

  sendChat(chat) {
    this.service.updateChatMessage(chat.$key, chat);
  }

  onActiveChat(chat) {
    this.activeChat = chat;
  }
}
<div class="chat-container">
  <div class="chat mat-elevation-z4">
    <mat-sidenav-container>
      <mat-sidenav class="mat-elevation-z2" mode="side" opened="true" #chatSidenav>
        <app-contacts [chats]="chats" (onActiveChat)="onActiveChat($event)"></app-contacts>
      </mat-sidenav>
      <app-chat [activeChat]="activeChat" [chatSidenav]="chatSidenav" (onSendChat)="sendChat($event)"></app-chat>
    </mat-sidenav-container>
  </div>
</div>

./chats.component.scss

$height__chat-header: 150px;
$height__chat-toolbar: 64px;
$height__chat-container: calc(
  100% - #{$height__chat-header - $height__chat-toolbar}
);

:host {
  display: block;
  height: 100%;
  position: relative;
}

.header {
  min-height: $height__chat-header;
  max-height: $height__chat-header;
  background-color: #3f51b5;
}

.chat-container {
  height: $height__chat-container;
  position: relative;
  max-width: 1200px;
  margin: 0 auto 0;
  padding: 0 32px 64px;

  .chat {
    background: white;
    height: 100%;

    mat-sidenav {
      width: 320px;
    }
  }
}

.cdk-focus-trap-content,
mat-sidenav {
  overflow-y: hidden !important;
  overflow-x: hidden;
}

mat-sidenav.mat-sidenav-opened.mat-elevation-z2,
mat-sidenav.mat-sidenav-opening.mat-elevation-z2 {
  box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14),
    0 1px 5px 0 rgba(0, 0, 0, 0.12);
}

.avatar {
  width: 40px;
  min-width: 40px;
  height: 40px;
  line-height: 40px;
  border-radius: 50%;
  text-align: center;
}

.chat-tips {
  color: #fff;
  font-size: 16px;
  padding-top: 10px;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""