1

I'm really new to Angular, but I'm working on a project with a team. After resolving a merge conflict, the application stopped displaying in my browser, and the console displays this error:

Uncaught Error: Can't resolve all parameters for StationComponent: (?, [object Object], [object Object], [object Object], [object Object], [object Object], ?).

From the error, it looks like the StationComponent's Constructor, and the two (?)'s in the error align with the StationService, and UserServices that are being imported. I don't know why this error is being thrown. Both services have the @Injectable annotation, and their import paths are correct (I've even has VSCode re-import them automatically). Can someone help me?

Here's the Component's class:

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { Station } from '../../models/station';
import { Rail } from '../../models/rail';
import { StationService } from '../../services/station.service';
import { DragulaService } from 'ng2-dragula/components/dragula.provider';
import { UtilsService } from '../../services/utils.service';
import { DialogService, DialogComponent } from 'ng2-bootstrap-modal';
import { AddRailComponent } from '../add-rail/add-rail.component';
import { Subject } from 'rxjs/Subject';
import { ApplicationRef } from '@angular/core';
import { UserService } from '../../services/user.service';


@Component({
  selector: 'app-station',
  templateUrl: './station.component.html',
  styleUrls: ['./station.component.css']
})


export class StationComponent implements OnInit {
public static refreshStation: Subject<boolean> = new Subject();

  station: Station; // = new Station(268, 'Station Name', null, null, [126, 127, 128], null);
  rails: Rail[] = [];

  roleId: number;
  constructor(
    private stationService: StationService,
    private route: ActivatedRoute,
    private dragula: DragulaService,
    private utilsService: UtilsService,
    private dialogService: DialogService,
    private appRef: ApplicationRef,
    private userService: UserService) {
    StationComponent.refreshStation.subscribe(
      res => {
        console.log('Refreshing...');
        this.getStation();
        this.getRails();
      }
    );
  }

  ngOnInit() {
    this.getStation();
    this.getRails();

    this.roleId = this.userService.getUsersRole().id;
    this.dragula.drop.subscribe(
      val => {
        this.station.railIds = this.utilsService.map(this.rails, e => e.railId);
        this.stationService.saveRailOrder(this.station);
      }
    );
  }

  getStation() {
    this.station = this.stationService.selected();
  }

  getRails() {
    if (this.station != null) {
      this.stationService.getRails(this.station)
        .subscribe(
        response => {
          this.rails = response;
        },
        err => this.handleError(err)
        );
    }
  }

  handleError(err) {
    console.log(err);
  }

  showAddRail() {
    const disposable = this.dialogService.addDialog(AddRailComponent, { station: this.station}).subscribe(resp =>
      this.stationService.refresh()
    );
  }

}
Sonic260
  • 25
  • 1
  • 5
  • Did you add the two services to the `providers` list of the module? – ConnorsFan Jan 28 '18 at 20:42
  • Yes, they're both here: providers: [ LoginService, StationService, UserService, ProfileService, LogoutService, RailService, RegisterService, GetStationsService, TileService, TaskService, UtilsService], – Sonic260 Jan 28 '18 at 20:49
  • Take a look at [this question](https://stackoverflow.com/q/37997824/1009922). In [one of the answers](https://stackoverflow.com/a/47517885/1009922), J MADISON recommends to check that all the service decorators are correctly spelled `@Injectable()`, not `Injectable()` or `@Injectable` or `@injectable()`. – ConnorsFan Jan 28 '18 at 20:58
  • There was one instance where changing the order of the UserService's import within the app.module.ts let it be found, but I've been unable to do the same for the StationService... – Sonic260 Jan 28 '18 at 22:04

2 Answers2

1

I am not sure I have enough to go on here. First thing I would check is to make sure all the services are properly imported as providers in the module or appmodule.

Streamweaver
  • 375
  • 2
  • 8
0
Uncaught Error: Can't resolve all parameters for StationComponent: (?, [object Object], [object Object], [object Object], [object Object], [object Object], ?).

From the error the '?' means that service is not able to get injected. So in your case '?' is located at the place of StationService and UserService. So make sure these two services are added in the providers array in app.module

Sumeet Kale
  • 365
  • 1
  • 11