我可以将ngx-bootstrap可排序组件与formArray一起使用吗?

时间:2020-06-02 10:41:12

标签: jquery-ui-sortable ngx-bootstrap

当我尝试将ngx-bootstrap可排序组件与formArray一起使用时,当我尝试混合使用反应式表单指令和bs-sortable组件时遇到了很多错误。

<ng-template #imageTemplate let-item="item" let-index="index"><span>{{index}}: <pre>{{item | json}}</pre></span></ng-template>
<bs-sortable
    [(ngModel)]="imagesFormArray.controls"
    [itemTemplate]="imageTemplate"
    itemClass="sortable-item"
    itemActiveClass="sortable-item-active"
    placeholderItem="Drag here"
    placeholderClass="placeholderStyle"
    wrapperClass="sortable-wrapper"
></bs-sortable>

我在控制台中看到的错误是

ERROR Error: 
  ngModel cannot be used to register form controls with a parent formGroup directive.  Try using
  formGroup's partner directive "formControlName" instead.`

如果我将ngModel更改为formArrayName,则没有错误,但是什么也没有输出。

官方文档只有ngModel方法,但这对我不起作用

1 个答案:

答案 0 :(得分:0)

尝试使用ngx-sortablejs。 就我而言,它就像一种魅力。