Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 反应形式:Can';t绑定到';formGroup';因为它不是';t'的已知属性;表格';_Angular - Fatal编程技术网

Angular 反应形式:Can';t绑定到';formGroup';因为它不是';t'的已知属性;表格';

Angular 反应形式:Can';t绑定到';formGroup';因为它不是';t'的已知属性;表格';,angular,Angular,所以我试图创建反应式表单,但终端抛出了一个错误,我无法理解这里的错误。 app.module.ts I中的P.S已导入ReactiveFormsModule 这是密码 <form [formGroup]="reciepeForm" (submit)="onSubmit()"> <div class="row"> <div class="c

所以我试图创建反应式表单,但终端抛出了一个错误,我无法理解这里的错误。 app.module.ts I中的P.S已导入ReactiveFormsModule

这是密码

  <form [formGroup]="reciepeForm" (submit)="onSubmit()">
            <div class="row">
                <div class="col-12">
                    <div class="btn btn-success" type="submit">Save</div>
                    <div class="btn btn-danger" type="button">Cancel</div>
                </div>
            </div>
            <div class="row">
                <div class="col-12">
                    <div class="form-group">
                        <label for="name">Name</label>
                        <input type="text" class="form-control" id='imagePath' formControlName="name">
                    </div>
                </div>
            </div>

        </form>
这里有一个错误

请确保:

  • 导入
    AppModule中的
    recipe edit.module.ts

  • AppModule

正如@totalynewb提到的,在
AppModule
中导入
FormsModule
ReactiveFormsModule

这是否回答了您的问题?正如@Totalynewb提到的,您需要在模块文件中导入
FormsModule
ReactiveFormsModule
。它已经导入了,这就是为什么我无法理解它为什么不能工作的原因。非常感谢,ReceipeeditComponent不在AppModule中,但我使用CLI创建了它,它必须自动导入。我说的对吗?在AppModule中声明它解决了您的问题吗?至于你的第二点,我不确定,因为这取决于你是如何用角CLIyes生成它的,它是如何求解的。。我刚刚在app.module中导入了组件。我像所有其他组件一样使用ng g c reciepe edit创建了它
  reciepeForm: FormGroup;
  this.reciepeForm = new FormGroup({
      'name': new FormControl(),
      'imagePath': new FormControl(),
      'description': new FormControl(),
    })