2016-12-16 7 views
1

dragulaServiceの最初の要素を移動させないようにしようとしていますが、このコードはエラーなしで初めて動作しますが、エラーが発生しました。ng2-dragulaを使用して2回目のページに移動する

エラーの原因となっているコード:

constructor(public service:SmartTablesService, private dragulaService:DragulaService) { 
    dragulaService.setOptions('nested-bag', { 
     revertOnSpill: true, 
     moves: function (el:any, container:any, handle:any):any { 
     if (handle.className === 'sorting-table-title') { 
      return false; 
     } else { 
      return true; 
     } 

     } 
    }); 

エラーがある:それは自動的に行われていないので、

error_handler.js:48 EXCEPTION: Uncaught (in promise): Error: Error in ./SortTableComponent class SortTableComponent_Host - inline template:0:0 caused by: Bag named: "nested-bag" already exists. Error: Bag named: "nested-bag" already exists. at DragulaService.add (http://platform.local:8080/3.chunk.js:1070:19) at DragulaService.setOptions (http://platform.local:8080/3.chunk.js:1099:24) at new SortTableComponent (http://platform.local:8080/3.chunk.js:1311:24)

答えて

5

が手動でコンポーネントのonDestroyライフサイクルにnested-bagを破壊する必要があります。

ngOnDestroy() { 
    this.dragulaService.destroy('nested-bag'); 
} 
関連する問題