我完全没有想法了。我想使用Reactive Forms模块,所以我将其导入到app.module.ts中,如下所示
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
...
],
imports: [
...
ReactiveFormsModule,
...
],
providers: [],
bootstrap: [AppComponent]
})在我的组件中我定义了:
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'));
}
}编译工作得很好,但是当显示它时,它会崩溃,并在浏览器控制台中显示以下错误:"core.js:6156 error Error: NG0201: No provider for NgControl for NodeInjector found“。
你们有谁知道哪里出了问题吗?
如果有任何提示,我将不胜感激。
非常感谢!
发布于 2021-03-27 05:51:28
要实现这一点,您必须将ReactiveFormsModule导入到您的@NgModule中,如您的问题所示,@NgModule就是ViewsModule。因为FormControl是作为ReactiveFormsModule的一部分而不是FormsModule公开的。
import { ReactiveFormsModule, ... } from '@angular/forms';
@NgModule({
imports: [..., ReactiveFormsModule, ...],
...
})
export class ViewsModule {...}https://stackoverflow.com/questions/65936059
复制相似问题