Can't resolve all parameters for UserService:(Http, ?)

angular

Solution

This might be due to this import statement

import { SubDomainService} from './index';

you might be exporting SubDomainService from a different file i.e. index.ts in your case, consider importing service directly from it's own file.

Problem

My project was working fine until i upgraded to recent Angular2 version 2.0.0-beta.17 My UserService is like this ``` import { Injectable} from '@angular/core'; import { Http } from '@angular/http'; import { BaseService } from './base.service'; import { SubDomain } from './../interfaces/subdomain.interface'; import { SubDomainService} from './index'; @Injectable() export class UserService extends BaseService { subDomain: SubDomain; constructor( private _http: Http, private subDomainService: SubDomainService ) { super(); this.subDomain = subDomainService.subDomain; } } ``` and SubDomainService is like this ``` import { Injectable } from '@angular/core'; import { SubDomain } from './../interfaces/subdomain.interface'; import { CompanyService } from './company.service'; @Injectable() export class SubDomainService { subDomain: SubDomain = { exists: false, is_sub_domain_url: false, sub_domain: '', company_id: '', user_id: '', name:'' }; constructor( private _companyService: CompanyService ) { } } ``` I looked up for solutions but most of them were about making a service injectable but here i followed the same convention but stilll it's giving the error Uncaught Error: Can't resolve all parameters for UserService: (Http, ?). My AppModule is like this ``` import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { CoreModule } from './core.module'; import { AppComponent } from './app.component'; import { routes } from './config/routes/index'; @NgModule({ declarations: [ AppComponent ], imports: [ routes, BrowserModule, CoreModule.forRoot() ], bootstrap: [AppComponent] }) export class AppModule { } ``` CoreModule is like this ``` import {ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; import { SubDomainService, CompanyService, UserService } from './shared/services/index'; import {SharedModule} from './shared/modules/shared.module'; @NgModule({ exports: [SharedModule] }) export class CoreModule { static forRoot(): ModuleWithProviders { return { ngModule: CoreModule, providers: [SubDomainService,UserService,CompanyService] }; } constructor( @Optional() @SkipSelf() parentModule: CoreModule) { if (parentModule) { throw new Error('CoreModule is already loaded. Import it in the AppModule only'); } } } ```

Original source