title: Cannot read property 'emit' of undefined typescript
body: <p>im building a simple chat app with socket io angular 2(typescript) and nodejs as a backend server 
  i have this function which works perfectly when i click the connect button</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>connectUser(name){
    
      
     if (name == null || name == ""){
     return  console.log('you must enter a valid username');
     
     }
     this.username = name;
  
     this.socket.emit('add-user',name);
     //load connected users in the user-window section
     this.socket.emit('request-users',{data:'request users success'});
     var connecctedUsersListener$ = Observable.fromEvent(this.socket,'users');
     connecctedUsersListener$.subscribe((observer:any)=&gt;{
      this.users = observer;
    },(err)=&gt;{
      if(err) throw err;
     },()=&gt;{
      console.log('complet');
     });
    
    //load messages and keep track of Them 
    this.socket.emit('request-messages',{data:'request Messages success'});
    var messageListener$ = Observable.fromEvent(this.socket,'message');
    messageListener$.subscribe((observer:any) =&gt;{
     this.messages = observer;
     
    })
  
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>however i try to use  bootbox.prompt whenever the user tries to connect so i wrap all the code inside this simple function </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>addUser(){
    bootbox.prompt('what is your name ',function(name){
    connectUser(name); // this is the function in the first code snippet  
  
       });
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>i get this wierd error <strong>Cannot read property 'emit' of undefined</strong>
  how can i fix that and what is the problem here ?</p>