0

I have an Angular 9 service which is running fine. However, upon attempting to push my data into a form, i created a new form by adding the following into the service:

import { FormGroup, FormBuilder } from '@angular/forms';

constructor(public formBuilder: FormBuilder) { }

newForm = new FormGroup({});

this.newForm = formBuilder.group({
  value_one: [''],
  value_two: [''],
});

Any time public formBuilder: FormBuilder is added to any of my services, I receive the error:

"Cannot instantiate cyclic dependency!"

If however, I decided to add those to the component.ts instead of the service, it's fine.

I've had this set up working fine in my Angular 8 project, so I'm wondering if anything has changed for A9 that I haven't noticed?

Thanks for any assistance!

Haven
  • 87
  • 1
  • 9
  • `this.newForm = formBuilder.group({ value_one: [''], value_two: [''], });` should be `this.newForm = this.formBuilder...`. – Ramesh Reddy Mar 05 '20 at 10:21
  • Yup, that was a typo for this question. Even if `this.newForm` isn't included and just the formBuilder added to the constructor, the error is received. – Haven Mar 05 '20 at 10:23
  • This may not be related to angular 9, here's a similar [question](https://stackoverflow.com/questions/47091872/angular-4-cannot-instantiate-cyclic-dependency-injectiontoken-http-interceptor) – Ramesh Reddy Mar 05 '20 at 10:28
  • Thanks. However, I'm not injecting another service and looping around as far as I can see. I have one component importing one service. That service works fine until a formBuilder is added. That's when it dies. – Haven Mar 05 '20 at 10:34
  • @Haven did you figure this out? I have the exact same problem having updated a project from Angular 8 to 10 and I just cant see a reason for it. – louisl Oct 14 '20 at 18:10

0 Answers0