以下是使用cdkDrag使其可拖动的项目的代码。
...
<div class="example-boundary">
<div class="example-box" cdkDragBoundary=".example-boundary" cdkDrag #dragitem>
I can only be dragged within the dotted container
</div>
</div>
...
import {Component} from '@angular/core';
/**
* @title Drag&Drop boundary
*/
@Component({
selector: 'cdk-drag-drop-boundary-example',
templateUrl: 'cdk-drag-drop-boundary-example.html',
styleUrls: ['cdk-drag-drop-boundary-example.css'],
})
export class CdkDragDropBoundaryExample {}
...
是否有一种方法可以使用cdkDrag API或其他类似方法以编程方式将拖动事件触发到特定位置??
类似这样的东西:
@ViewChild('dragitem') dragItemRef: ElementRef
someMethod() {
this.dragItemRef.fire('dragmove', {x: 30, y: 120})
//or this.dragItemRef.dispatchEvent('dragmove', {x: 30, y: 120})
}