Dragula :revert drop in ng2-dragula

早过忘川 提交于 2019-12-12 10:53:49

问题


i have an angular2 app with typescript. I am using ng2-dragula to make a drag and drop application.

I am requiered to, check a condition, and revert the drag if the condition is false, and I know from here, that revertOnSpill that revertOnSpill:true can put the element back to its first place.

But, I don't know how is it possible in ng2-dragula. i implimented it in the onDrop. here is the code

 constructor() {

              dragulaService.drop.subscribe((value) => {
                  this.onDrop(value.slice(1));
              });

                dragulaService.setOptions('second-bag', {
                  removeOnSpill: true
              });
 }

private onDrop(args) {
   bla
   bla
   bla
   if(err.status=="404")                                                               
          this.dragulaService.removeModel;
         // this.dragulaService.cancel; also tried but did not work   
}

and here is the html code:

<div   id="toPlay" class="playBox roundedBox" [dragula]="'second-bag'">
    <img class="w3-animate-top" [src]="sax_path" alt="sax" id="saxsophone"/>
    <img class="w3-animate-top" [src]="drum_path" alt="drum" id="drum"/> 
</div>
<div   id="scene"  [dragula]="'second-bag'">

</div> 

Package.json is:

 "dependencies": {
    "dragula": "^3.7.2"
  },
  "peerDependencies": {
    "@angular/common": "^2.0.0",
    "@angular/core": "^2.0.0",
    "@angular/compiler": "^2.0.0",
    "@angular/forms": "^2.0.0"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.22-1",
    "typescript": "2.0.10"
  }

the problem is, i don't know how to cancel the drop?


回答1:


There is a property called boolean moves, which controls iff an element is movable or not

this.dragulaService.setOptions('second-bag', {

        moves:  (el, container, handle) =>{

                             if(YourCondition)
                                     //return true;
                             else
                                     //return false; 
                         }))


来源:https://stackoverflow.com/questions/41512773/dragula-revert-drop-in-ng2-dragula

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!