i ran completly out of ideas. I want to user Reactive Forms Module, so i imported it in app.module.ts like
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    ...
    ReactiveFormsModule,
    ...
  ],
  providers: [],
  bootstrap: [AppComponent]
})
In my Component i defined:
import { Component, OnInit} from "@angular/core";
import { FormControl, FormGroup } from '@angular/forms';
@Component({
    ...
})
export class SearchComponent implements OnInit{
    //Variablen
    form: FormGroup;
    
    //Konstruktor
    constructor(){}
    //Methoden
    ngOnInit(){
        this.form = new FormGroup({
            'title': new FormControl(null)
        });
    }
    showValue(){
        console.log(this.form.get('title'));
    }
}
Compiling works well, but when displaying it it crashes with the error below shown in the Browser Console: "core.js:6156 ERROR Error: NG0201: No provider for NgControl found in NodeInjector."
Does anybody of you has an idea what went wrong?
I would really appreciate any hint.
Thanks a lot!
To make this work you'll have to import the ReactiveFormsModule in your @NgModule which is the ViewsModule as your question suggests. As FormControl is exposed as a part of ReactiveFormsModule and NOT the FormsModule.
import { ReactiveFormsModule, ... } from '@angular/forms';
@NgModule({
  imports: [..., ReactiveFormsModule, ...],
  ...
})
export class ViewsModule {...}
Just found my (same) mistake, you have to import ReactiveFormsModule in "local" module...
In your case it must be "search-component.module.ts"
import FormsModule as well in app.module.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With