0

I am getting the following error for a service: Uncaught Error: Can't resolve all parameters for FormFlowService: (AnnounceObjectService, ?)

I have no red lines coming up and I have declared the service in my app module. Does any one know the reason? Note I am using FormService in other services without this error.

My service looks like:

import { Injectable } from '@angular/core';
import { FormService } from './form.service';
import { FormFlow, FormFlowTask, FormTaskReference, FormTaskAssign, FormTask, FormTaskState, FormTaskAssignActive } from './form';
import { AnnounceObjectService } from '../../../shared/services/announce-object/announce-object.service';
import * as _ from "lodash"; //Will be red but stil works
import { Subscription }   from 'rxjs/Subscription';

@Injectable()
export class FormFlowService {
  subscription: Subscription;
  tasks: FormFlowTask[];
  taskReference: FormTaskReference;
  flow: FormFlow;
  stateList: FormTaskState[];
  taskList: FormTask[];  
  assignList: FormTaskAssign[];
  stateListBase: number;
  assignListBase: number;  
  isQueFlow: boolean;
  constructor(private announceObjectService: AnnounceObjectService, private formService: FormService) { 

  }   

}

App Module:

@NgModule({
  declarations: [
    AppComponent  
  ],
  entryComponents: [
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing,
    MaterialModule.forRoot(),
    FlexLayoutModule.forRoot()
  ],
  providers: [
  { provide: LOCALE_ID, useValue: 'en-AU' },
  AUTH_PROVIDERS, 
  FormService, 
  FormFlowService,
  FormElementService,
  AnnounceObjectService

  ],
  bootstrap: [AppComponent]
})
Ka Tech
  • 8,937
  • 14
  • 53
  • 78
  • Where did you provide `FormFlowService`, `AnnounceObjectService` and `FormService`? – Günter Zöchbauer Feb 06 '17 at 12:28
  • Added my app module, I provide it in providers: []. The thing is I get no error with when I declare FormService in FormElementService – Ka Tech Feb 06 '17 at 12:34
  • What does the constructor of `AnnounceObjectService` look like. Does the `@Injectable()` decorator have the parens? Is the import path correct? – Günter Zöchbauer Feb 06 '17 at 12:43
  • @Injectable() export class AnnounceObjectService { private objectAnnouncedSource = new Subject(); objectAnnouncedSource$ = this.objectAnnouncedSource.asObservable(); constructor() { } announceObject(announceObject: AnnounceObject) { // Type + obj this.objectAnnouncedSource.next(announceObject); } } – Ka Tech Feb 06 '17 at 12:45
  • 1
    Please edit the question and add the code there. Code in comments is unreadable. – Günter Zöchbauer Feb 06 '17 at 12:47
  • I don't think announceObjectService is the issue. I think I found the issue. In my FormService constructor I inject FormFlowService. And in FormFlowService constructor I inject FormService. Seems like Angular doesn't like it both ways. – Ka Tech Feb 06 '17 at 12:54
  • 1
    You can work around circular dependency using http://stackoverflow.com/questions/40525850/circular-dependency-injection-angular-2/40525992#40525992 – Günter Zöchbauer Feb 06 '17 at 12:58
  • Thanks Gunter that resolved the issue! – Ka Tech Feb 06 '17 at 20:50

0 Answers0