forked from start-angular/angular2-node-socket-io-chat-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nickName.component.ts
41 lines (30 loc) · 899 Bytes
/
nickName.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Component } from "@angular/core";
import { Router } from "@angular/router";
import * as globalVars from "../service/global";
import {Inject} from "@angular/core";
/// <reference path="../../typings/globals/jquery/index.d.ts/>
import "/socket.io/socket.io.js";
@Component({
moduleId: module.id,
selector: "nick-name",
templateUrl: "nickName.component.html"
})
export class NickNameComponent {
nickname: string = null;
protected router;
constructor( @Inject(Router) router: Router) {
this.router = router;
}
submit(data) {
this.nickname = data.value;
if (this.nickname) {
globalVars.socket = io({ query: "userName=" + this.nickname });
this.router.navigate(["chat"]);
}
}
addNickname($event, nickname) {
if ($event.which === 13) { // ENTER_KEY
this.submit(nickname);
}
}
}