我正在使用 Angular 2 和ng2-dragula
.
我想让拖拉袋中的拖放项目可点击。
这是我的app.component.html:
<div id="rootFrame">
<div class="tasksFrame">
<div id="tasksCont" class='container' [dragula]='"first-bag"'>
<div (click)="onClick('ha')">Task 1</div>
<div (click)="onClick('ba')">Task 2</div>
<div (click)="onClick('ca')">Task 3</div>
</div>
</div>
<div class="editorFrame">
<div id="editorCont" class='container' [dragula]='"first-bag"'>
</div>
</div>
<div *ngIf="showProps" class="propertiesFrame">
<form>
Eigenschaft 1<br>
<input type="text" name="property1"><br> Eigenschaft 2<br>
<input type="text" name="property2"><br> Eigenschaft 3<br>
<input type="text" name="property3"><br>
</form>
</div>
</div>
该onClick()
函数永远不会被调用。
我的组件app.component.ts如下所示:
import { Component } from '@angular/core';
import { DragulaService } from 'ng2-dragula/ng2-dragula';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
styleUrls: ['app/app.component.css'],
viewProviders: [DragulaService],
})
export class AppComponent {
private showProps = false;
constructor(private dragulaService: DragulaService) {
dragulaService.setOptions('first-bag', {
removeOnSpill: true,
copy: (el: Element, target: Element, source: Element, sibling: Element): boolean => {
var editorcont = document.getElementById('editorCont');
return !target.contains(editorcont);
},
accepts: (el: Element, target: Element, source: Element, sibling: Element): boolean => {
var taskscont = document.getElementById('tasksCont');
return !target.contains(taskscont); // elements can not be dropped to Tasks Container
},
});
};
onClick(item: String) {
//NOT FIRED
var editorcont = document.getElementById('editorCont');
// if(editorcont.contains(element)){
// this.showProps = true;
// }
// else{
// this.showProps = false;
// }
};
}
我认为这是因为 div 在 Dragula 容器中。但是我怎样才能让 Dragula 容器中的 div 可以点击呢?