gempir gempir - 1 year ago 258
AngularJS Question in Angular 2 app

I'm trying to use the client in my angular 2 app and installed it and typings

I'm just importing from '';

but somehow I get tons of errors from that:

enter image description here

I can use the lib in my index.html if I load the script from a cdn and just put the init code in a

tag but I can't use it in my actual angular 2 app.

What am I doing wrong here?

This is my boilerplate:

The examples for seem outdated which is why I avoided them.

this is all i'm doing and already getting those errors:

import * as io from '';
var socket = io('');

So the issue seems to be related to SystemJS in someway.
This suggests I can add the and it should add all dependencies automaticly that doesn't seem the case though.

I've tried the full example but that won't work either.

Answer Source

I am using socket io in my angular-cli based project. It was easy to configure. Let me show you my configuration-

First you have to

npm install --save

Then, open your angular-cli-build.js and add '**/*.*' like this way-

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [

Open your system-config.ts under src and add like this way

 * User Configuration.
/** Map relative paths to URLs. */
const map: any = {
  '' : 'vendor/'

/** User packages configuration. */
const packages: any = {
  '' : {main: ''}

Add <script src="vendor/"></script> in your src/index.html(Yes, It is so much important)

Now, It is you and your code. I added my socket io in a service

import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import * as io from '';

export class ChatService {
  private url = 'http://localhost:5000';  
  private socket;

    this.socket.emit('add-message', message);    

  getMessages() {
    let observable = new Observable(observer => {
      this.socket = io(this.url);
      this.socket.on('message', (data) => {;    
      return () => {
    return observable;

I am using 2.0.0-rc.4 and my angular-cli version is 1.0.10-beta and version is": "^1.4.6. It worked for me, and it will definitely work for you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download