title: How to pass parameters for dependency while Injecting services in services in Angular 2 ( Ionic 2 / Angular 2 / Typescript )
body: <p>I'm making a sample application to make connection to a websocket server in ionic 2 in typescript. link to <a href="https://github.com/mehdhi/ionic2websocketconnectionsample">repo</a> </p>
  
  <p>My requirement is to make the websocket connection during application start up</p>
  
  <p>I'm using <a href="https://github.com/afrad/angular2-websocket">angular2-websocket</a> to creating the connection.</p>
  
  <p>References :</p>
  
  <ol>
  <li><p><a href="http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html">http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html</a></p></li>
  <li><p><a href="http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html">http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html</a></p></li>
  </ol>
  
  <p>I'm getting a error " Cannot resolve all parameters for '$WebSocket'(String, Array, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that '$WebSocket' is decorated with Injectable. "</p>
  
  <p>CODE:
  <a href="https://github.com/mehdhi/ionic2websocketconnectionsample/blob/master/app/app.ts">app.ts</a></p>
  
  <pre><code>import {App, Platform} from 'ionic-framework/ionic';
  import {TabsPage} from './pages/tabs/tabs';
  import {ConnectionService} from './framework/connection/connection-service'
  import {$WebSocket} from 'angular2-websocket/angular2-websocket';
  import {bootstrap} from 'angular2/platform/browser';
  
  // https://angular.io/docs/ts/latest/api/core/Type-interface.html
  import {Type} from 'angular2/core';
  
  
  @App({
    template: '&lt;ion-nav [root]="rootPage"&gt;&lt;/ion-nav&gt;',
    config: {}
  })
  export class MyApp {
    rootPage: Type = TabsPage;
  
    constructor(platform: Platform, private conn : ConnectionService) {
      platform.ready().then(() =&gt; {
        this.conn.connect();
      });
    }
  }
  bootstrap(MyApp, [$WebSocket, ConnectionService]);
  </code></pre>
  
  <p><a href="https://github.com/mehdhi/ionic2websocketconnectionsample/blob/master/app/framework/connection/connection-service.ts">connection-service.ts</a></p>
  
  <pre><code>import {Injectable, Component, Inject} from 'angular2/core';
  import {$WebSocket} from 'angular2-websocket/angular2-websocket';
  import {bootstrap} from 'angular2/platform/browser';
  
  @Injectable()
  export class ConnectionService {
  
      private _status: number;
  
      //private connection: $WebSocket;
  
      constructor( private connection : $WebSocket = new $WebSocket("ws://echo.websocket.org") ) {
  
      console.log("Starting connection");
  
     //this.connection = new $WebSocket("ws://echo.websocket.org");
  
      this.connection.onClose(this.onCloseHandler);
      this.connection.onError(this.onErrorHandler);
      this.connection.onOpen(this.onOpenHandler);
      this.connection.onMessage(this.onRecieveHandler, {});
  
  }
  ...
  public connect() {
      this.connection.connect(true);
  }
  ...
  }
  bootstrap(ConnectionService, [$WebSocket]);
  </code></pre>