角度 – Dragula:恢复ng2-dragula的下降

前端之家收集整理的这篇文章主要介绍了角度 – Dragula:恢复ng2-dragula的下降前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有打字稿的angular2应用程序.我使用 ng2-dragula来制作拖放应用程序.

我需要检查条件,如果条件为假则恢复拖动,我知道从here开始,revertOnSpill revertOnSpill:true可以将元素放回到第一位.

但是,我不知道在ng2-dragula中怎么可能.
 我在onDrop中赞美它.这是代码

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   
}

这是HTML代码

<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是:

"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"
  }

问题是,我不知道如何取消掉落?

解决方法

有一个名为boolean moves属性,它控制iff元素是否可移动

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

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

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

猜你在找的Angularjs相关文章