Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Is it possible to Mock an Angular FormGroup by creating a Provider?

I want to create a "Testbed" for storybook and embed a component which requires a FormGroup on a parent DOM element. Is it possible to skip the template and pass all required elements to the reactive form control by providing an Injectable?

Before:

<div [formGroup]='formGroupA'>
   <app-example-field formControlName='example'></app-example-field>
</div>
import { FormGroup } from '@angular/forms';
// e.g.
const formGroup = new FormGroup({
  example: new FormControl('')
});

After: Direct template

<app-example-field formControlName='example'></app-example-field>
import { FormGroup, ReactiveFormsModule } from '@angular/forms';

// Storybook (should work in the same way as a standalone Module + Component) ... 
  decorators: [
    moduleMetadata({
      imports: [
        MyExampleModule,
        ReactiveFormsModule
      ],
      providers: [
        // What to put here?
      ]
    })
  ],

Without a valid formGroup the angular directive formControlName throws an error: ERROR Error: formGroup expects a FormGroup instance. Please pass one in.

Any idea? How to pass this issue?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!