import { Component , OnInit , NgZone } from '@angular/core' ; import { RouterExtensions } from 'nativescript-angular/router' ; import { SocketIO } from 'nativescript-socketio' ; @ Component ( { selector : 'login' , moduleId : module . id , templateUrl : './login.component.html' , styleUrls : [ './login.component.css' ] } ) export class LoginComponent implements OnInit { username = '' ; constructor ( private router , private socketIO , private ngZone ) { } ngOnInit ( ) { this . socketIO . on ( 'login' , data => { this . ngZone . run ( ( ) => { console . log ( 'Username: ' + this . username ) ; this . router . navigate ( [ 'main-page' , this . username ] ) ; } ) ; } ) ; this . socketIO . connect ( ) ; } join ( username ) { this . username = username ; this . socketIO . emit ( 'add user' , { username } , ( ack ) => { console . log ( 'ack' , ack ) ; } ) ; } }