0

我有一个日期选择器,其中输入字段和弹出窗口的配置如下所述: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) 具有处理函数,该函数从 的模型中获取 endDate 值NgbDateStruct,获取其日/月/年并将其放入我的 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
4

1 回答 1

0

它不再被复制,因为我已经从那里删除了 formControlName="completed" 并且只剩下 [(ngModel)]

于 2020-10-06T11:55:40.130 回答