Can't resolve all parameters for SocketProvider: ([object Object], [object Object], [object Object], ?, [object Object], [object Object], [object Object])

Hi there, I was trying to import a provider into another but I got this error I can’t really say what could be the cause. Below is my code.

In my ChatProvider class

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { SocketProvider } from "../socket/socket";
import { DataProvider } from "../data/data";

@Injectable()

export class ChatProvider {

  constructor(
    public http: Http,
    private socket: SocketProvider, // When I comment out this line I don't get the error
    public data: DataProvider
    ) {
      
  }

sendMessage(msg){
  this.socket.sendMessage(msg, (data) => {

 }
}
}

I have import this same SocketProvider in other page and didn’t get error.

The position of the ‘?’ tells you which is the problematic parameter. Possibly a circular dependency?

Thanks for the hint, Yes it’s a circular dependency. How can I go about this?

In general, I think circular dependencies indicate a design flaw, because the two classes are too tightly coupled. If you can’t eliminate it by design means, you can look into using forwardRef.

1 Like

Thank you for the swift response, I will look into that.