要实现Angular中的可排序的嵌套拖放,可以使用第三方库ngx-drag-drop。
首先,确保已经安装了ngx-drag-drop库:
npm install ngx-drag-drop
下面是一个示例代码,演示了如何使用ngx-drag-drop库实现可排序的嵌套拖放:
首先,在app.module.ts文件中导入DragDropModule:
import { DragDropModule } from 'ngx-drag-drop';
@NgModule({
  imports: [
    DragDropModule
  ],
  ...
})
export class AppModule { }
然后,在app.component.html文件中添加拖放区域的标记:
  
    
      
        {{ item.name }}
         0">
          
            {{ child.name }}
          
        
      
    
  
在app.component.ts文件中,定义要拖放的数据模型和拖放行为:
import { Component } from '@angular/core';
import { DragulaService } from 'ngx-drag-drop';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  items = [
    {
      name: 'Item 1',
      children: [
        {
          name: 'Child 1'
        },
        {
          name: 'Child 2'
        }
      ]
    },
    {
      name: 'Item 2',
      children: [
        {
          name: 'Child 3'
        },
        {
          name: 'Child 4'
        }
      ]
    }
  ];
  constructor(private dragulaService: DragulaService) {
    dragulaService.createGroup('nested-bag', {
      moves: (el, container, handle) => {
        // 只允许拖放box元素
        return handle.classList.contains('box');
      }
    });
  }
}
最后,在app.component.css文件中,定义拖放的样式:
.container {
  margin-top: 20px;
}
.box {
  padding: 10px;
  border: 1px solid #ccc;
  background-color: #f5f5f5;
  margin-bottom: 10px;
  cursor: move;
}
.nested-list {
  margin-left: 20px;
}
.nested-item {
  padding: 10px;
  border: 1px solid #ccc;
  background-color: #f5f5f5;
  margin-bottom: 10px;
  cursor: move;
}
这样,你就可以在Angular应用中使用ngx-drag-drop实现可排序的嵌套拖放。