Angular 7 Drag and Drop - Dynamically Create Drop Zones

后端 未结 6 715
无人及你
无人及你 2021-01-31 18:12

Is there a way to dynamically create drop zones? I\'m having some troubles with ngFor and cdkDropList.

Here is my first list and draggable elements:

           


        
6条回答
  •  孤街浪徒
    2021-01-31 18:58

    I had also to face to that problem. I tried the id approach but I didn't feel too much too confident while using. When I console.log in this addId() function, I can see the same id repeated several times. Instead of that, I tried to use the @ViewChildren decorator to have the cdkList components in real time, and it works very well for me.

    In typescript

      cdkDropTrackLists: CdkDropList[];
      @ViewChildren(CdkDropList)
      set cdkDropLists(value: QueryList) {
        this.cdkDropTrackLists = value.toArray();
      }
    

    In template

    I think I can improve it while cdkDropLists as a QueryList has a changes properties which an Observable.

提交回复
热议问题