Error: "formControlName must be used with a parent formGroup directive." for <input ngbDatepicker #e="ngbDatepicker" (click)="e.toggle()">
Error: "formControlName must be used with a parent formGroup directive." for <input ngbDatepicker #e="ngbDatepicker" (click)="e.toggle()">
我有一个日期选择器,其输入字段和弹出窗口按照此处所述配置:https://ng-bootstrap.github.io/#/components/datepicker/overview
所以,我有
1) 在模板中完成所有需要的导入的标签:
<input id="field_completed" [(ngModel)]="endDate" type="text" class="form-control" name="completed" formControlName="completed" placeholder="YYYY-MM-DD" ngbDatepicker #ended="ngbDatepicker" (click)="ended.toggle()" (dateSelect)="addEndDateAutomatically()"/>
2) 具有处理函数,它从 NgbDateStruct
的模型中获取 endDate 值,获取它的 day/month/year 并放入我的 DTO 以发送到服务器
我不明白,为什么只有当我在模板中使用了 ngbDatepicker
时才会出现以下错误,而当它被排除在外时却不会:
main.99b988e9722c4de65a1a.bundle.js:1 ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
directive and pass it an existing FormGroup instance (you can create one in your class).
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
at Function.l.controlParentException (main.99b988e9722c4de65a1a.bundle.js:1)
at n._checkParentType (main.99b988e9722c4de65a1a.bundle.js:1)
at n._setUpControl (main.99b988e9722c4de65a1a.bundle.js:1)
at n.ngOnChanges (main.99b988e9722c4de65a1a.bundle.js:1)
at main.99b988e9722c4de65a1a.bundle.js:1
at main.99b988e9722c4de65a1a.bundle.js:1
at Aw (main.99b988e9722c4de65a1a.bundle.js:1)
at sx (main.99b988e9722c4de65a1a.bundle.js:1)
at Object.updateDirectives (main.99b988e9722c4de65a1a.bundle.js:1)
at Object.updateDirectives (main.99b988e9722c4de65a1a.bundle
它不再被复制,因为我已经从那里删除了 formControlName="completed",只剩下 [(ngModel)]
我有一个日期选择器,其输入字段和弹出窗口按照此处所述配置:https://ng-bootstrap.github.io/#/components/datepicker/overview
所以,我有
1) 在模板中完成所有需要的导入的标签:
<input id="field_completed" [(ngModel)]="endDate" type="text" class="form-control" name="completed" formControlName="completed" placeholder="YYYY-MM-DD" ngbDatepicker #ended="ngbDatepicker" (click)="ended.toggle()" (dateSelect)="addEndDateAutomatically()"/>
2) 具有处理函数,它从 NgbDateStruct
的模型中获取 endDate 值,获取它的 day/month/year 并放入我的 DTO 以发送到服务器
我不明白,为什么只有当我在模板中使用了 ngbDatepicker
时才会出现以下错误,而当它被排除在外时却不会:
main.99b988e9722c4de65a1a.bundle.js:1 ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
directive and pass it an existing FormGroup instance (you can create one in your class).
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
at Function.l.controlParentException (main.99b988e9722c4de65a1a.bundle.js:1)
at n._checkParentType (main.99b988e9722c4de65a1a.bundle.js:1)
at n._setUpControl (main.99b988e9722c4de65a1a.bundle.js:1)
at n.ngOnChanges (main.99b988e9722c4de65a1a.bundle.js:1)
at main.99b988e9722c4de65a1a.bundle.js:1
at main.99b988e9722c4de65a1a.bundle.js:1
at Aw (main.99b988e9722c4de65a1a.bundle.js:1)
at sx (main.99b988e9722c4de65a1a.bundle.js:1)
at Object.updateDirectives (main.99b988e9722c4de65a1a.bundle.js:1)
at Object.updateDirectives (main.99b988e9722c4de65a1a.bundle
它不再被复制,因为我已经从那里删除了 formControlName="completed",只剩下 [(ngModel)]