Open prythms opened 3 years ago
ng-drag-drop Drop not working. dropping an item does nothing
npm install ng-drag-drop --save
Import NgDragDropModule import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { DemoComponent } from "./components/demo-component"; import { NgDragDropModule } from 'ng-drag-drop'; @NgModule({ imports: [ BrowserModule, NgDragDropModule.forRoot() ], declarations: [DemoComponent], bootstrap: [DemoComponent] }) export class AppModule {}
ts code
import {Component} from '@angular/core'; @Component({ selector: 'app', template: ` <div class="row"> <div class="col-sm-3"> <ul class="list-group"> <li draggable *ngFor="let item of items" [dragData]="item" class="list-group-item">{{item.name}}</li> </ul> </div> <div class="col-sm-3"> <div class="panel panel-default" droppable (onDrop)="onItemDrop($event)"> <div class="panel-heading">Drop Items here</div> <div class="panel-body"> <li *ngFor="let item of droppedItems" class="list-group-item">{{item.name}}</li> </div> </div> </div> </div> ` }) export class AppComponent { items = [ {name: "Apple", type: "fruit"}, {name: "Carrot", type: "vegetable"}, {name: "Orange", type: "fruit"}]; onItemDrop(e: any) { // Get the dropped data here this.droppedItems.push(e.dragData); } constructor() { } }
ng-drag-drop Drop not working. dropping an item does nothing
npm install ng-drag-drop --save
ts code