角4:ngb-dropdown-formcontrolName不起作用

时间:2018-09-20 05:33:50

标签: angular angular-reactive-forms ng-bootstrap

我正在使用ng-bootstrap": "1.0.0-alphaangular version 4.3.1。我正在尝试使用formControlName中的reactive-forms。这是我的代码段。

<div class="dropdown dropdown-val-label" ngbDropdown #suggestionDropDown="ngbDropdown" [autoClose]="true">
  <button [formControlName]="field.fieldName" class="btn btn-sm btn-secondary mw-100 dropdown-btn-toggle edit-custom-input"
    ngbDropdownToggle> Select</button>
  <div class="dropdown-menu dynamic-dropdown">
    <div class="dynamic-list-wrapper" virtualScroll [childHeight]="12" #scrollingBlock [items]="metadataList[field.fieldName]">
      <div #container>
        <div *ngFor="let item of  scrollingBlock.viewPortItems | slice:0:10">
          <a class="dropdown-item">{{item.name}}</a>
        </div>
      </div>
    </div>
  </div>
</div>

我的metadataList[field.fieldName]返回对象,例如{"id": 1, "name": "xyz"}

表单对象

  setForGroup(row) {
    let _self = this;
    let tmpFormGroups = {};
    _.each(row.groups, function (obj: any) {
      let tmpGroup: any = {};
      _.each(obj.value, function (aryObj: any) {
        tmpGroup[aryObj.fieldName] = aryObj.value;
      });
      tmpFormGroups[obj.key] = _self.fb.array([
        _self.fb.group(tmpGroup)
      ]);

    });
    this.formGroupObj = _self.fb.group(tmpFormGroups);
  }

enter image description here

0 个答案:

没有答案