Angular CDK drag-drop API 参考文档
import {DragDropModule} from '@angular/cdk/drag-drop';
服务
DragDrop
允许把拖放功能附加到 DOM 元素上的服务。
Service that allows for drag-and-drop functionality to be attached to DOM elements.
方法
createDrag | |
---|---|
把一个元素变成一个可拖动的条目。 Turns an element into a draggable item. |
|
参数 Parameters |
|
element HTMLElement | ElementRef<HTMLElement>
|
要附加拖动功能的元素。 Element to which to attach the dragging functionality. |
config DragRefConfig = DEFAULT_CONFIG
|
用于配置拖动行为的对象。 Object used to configure the dragging behavior. |
返回值 Returns |
|
DragRef<T>
|
|
createDropList | |
---|---|
把一个元素转成一个拖放列表。 Turns an element into a drop list. |
|
参数 Parameters |
|
element HTMLElement | ElementRef<HTMLElement>
|
要附加投放列表功能的元素。 Element to which to attach the drop list functionality. |
返回值 Returns |
|
DropListRef<T>
|
|
指令
CdkDropList
包装一组可拖动条目的容器。
Container that wraps a set of draggable items.
属性
名称 | 描述 |
---|---|
@Input('cdkDropListAutoScrollDisabled')
|
用户将指针移到边缘附近时是否自动滚动视图。 Whether to auto-scroll the view when the user moves their pointer close to the edges. |
@Input('cdkDropListAutoScrollStep')
|
当自动滚动元素时,这是每一帧滚动的像素数。 Number of pixels to scroll for each frame when auto-scrolling an element. |
@Input('cdkDropListConnectedTo')
|
此容器连接到的其他可拖动容器,此容器中的条目可以转移到其中。可以是到其他投放容器的引用,也可以是其唯一 ID。 Other draggable containers that this container is connected to and into which the container's items can be transferred. Can either be references to other drop containers, or their unique IDs. |
@Input('cdkDropListData')
|
附加到此容器的任意数据。 Arbitrary data to attach to this container. |
@Input('cdkDropListDisabled')
|
是否禁用了从此容器启动拖曳序列的方法。 Whether starting a dragging sequence from this container is disabled. |
@Input('cdkDropListEnterPredicate')
|
此函数用于确定是否允许将条目移入投放容器。 Function that is used to determine whether an item is allowed to be moved into a drop container. |
@Input()
|
投放区的唯一 ID。可以在 Unique ID for the drop zone. Can be used as a reference
in the |
@Input('cdkDropListLockAxis')
|
沿着指定的轴锁定容器内可拖动元素的位置。 Locks the position of the draggable elements inside the container along the specified axis. |
@Input('cdkDropListOrientation')
|
列表的方向。 Direction in which the list is oriented. |
@Input('cdkDropListSortPredicate')
|
一个函数,用来判断某个条目是否可以被排序到特定索引。 Functions that is used to determine whether an item can be sorted into a particular index. |
@Input('cdkDropListSortingDisabled')
|
是否禁用此投放列表中的排序。 Whether sorting within this drop list is disabled. |
@Output('cdkDropListDropped')
|
当用户把一个条目投放进该容器时就会触发。 Emits when the user drops an item inside the container. |
@Output('cdkDropListEntered')
|
当用户把一个新的拖动条目移到这个容器中时,就会触发。 Emits when the user has moved a new drag item into this container. |
@Output('cdkDropListExited')
|
当用户通过将条目拖到另一个容器中来将其从容器中移除时发出。 Emits when the user removes an item from the container by dragging it into another container. |
@Output('cdkDropListSorted')
|
当用户正在主动拖动以交换条目时,就会触发。 Emits as the user is swapping items while actively dragging. |
|
Element that the drop list is attached to. |
方法
addItem | |
---|---|
在投放列表中注册一个条目。 Registers an items with the drop list. |
|
参数 Parameters |
|
item CdkDrag<any>
|
|
getSortedItems | |
---|---|
获取列表中的已注册条目,按其在 DOM 中的位置排序。 Gets the registered items in the list, sorted by their position in the DOM. |
|
返回值 Returns |
|
CdkDrag[]
|
|
removeItem | |
---|---|
从投放列表中删除一个条目。 Removes an item from the drop list. |
|
参数 Parameters |
|
item CdkDrag<any>
|
|
CdkDropListGroup
声明性地将同级 cdkDropList
实例连接在一起。放置在 cdkDropListGroup
内的所有 cdkDropList
元素将自动互连。可作为 cdkDropList
的输入属性 cdkDropListConnectedTo
的替代品。
Declaratively connects sibling cdkDropList
instances together. All of the cdkDropList
elements that are placed inside a cdkDropListGroup
will be connected to each other
automatically. Can be used as an alternative to the cdkDropListConnectedTo
input
from cdkDropList
.
属性
名称 | 描述 |
---|---|
@Input('cdkDropListGroupDisabled')
|
是否禁止从该组内部开始拖动序列。 Whether starting a dragging sequence from inside this group is disabled. |
CdkDrag
可以在 CdkDropList 容器内移动的元素。
Element that can be moved inside a CdkDropList container.
属性
名称 | 描述 |
---|---|
@Input('cdkDragBoundary')
|
本节点或选择器将用于确定用来限制可拖动对象位置的元素。如果传入了一个字符串,它将用作选择器,该选择器将从元素的父级开始一直沿 DOM 进行匹配,直到找到匹配项为止。 Node or selector that will be used to determine the element to which the draggable's position will be constrained. If a string is passed in, it'll be used as a selector that will be matched starting from the element's parent and going up the DOM until a match has been found. |
@Input('cdkDragConstrainPosition')
|
本函数用于自定义在拖动条目时如何限制其位置的逻辑。使用用户指针在页面上的当前位置进行调用,并且要返回描述该条目应该出现在哪里的点。 Function that can be used to customize the logic of how the position of the drag item is limited while it's being dragged. Gets called with a point containing the current position of the user's pointer on the page and should return a point describing where the item should be rendered. |
@Input('cdkDragData')
|
要附加到此拖动实例的任意数据。 Arbitrary data to attach to this drag instance. |
@Input('cdkDragDisabled')
|
是否已禁止拖动此元素。 Whether starting to drag this element is disabled. |
@Input('cdkDragStartDelay')
|
用户放下指针后到开始拖动元素之前要等待的毫秒数。 Amount of milliseconds to wait after the user has put their pointer down before starting to drag the element. |
@Input('cdkDragFreeDragPosition')
|
设置投放容器外部的 Sets the position of a |
@Input('cdkDragLockAxis')
|
锁定所拖动元素沿指定轴的位置。 Locks the position of the dragged element along the specified axis. |
@Input('cdkDragPreviewClass')
|
要添加到预览元素中的类。 Class to be added to the preview element. |
@Input('cdkDragRootElement')
|
本选择器用于在 DOM 树中从本 Selector that will be used to determine the root draggable element, starting from
the |
@Output('cdkDragDropped')
|
当用户把条目放到容器中时,就会触发。 Emits when the user drops the item inside a container. |
@Output('cdkDragEnded')
|
当用户停止拖动容器中的某个条目时,会发出本通知。 Emits when the user stops dragging an item in the container. |
@Output('cdkDragEntered')
|
当用户把本条目移到新容器中时发出通知。 Emits when the user has moved the item into a new container. |
@Output('cdkDragExited')
|
当用户通过把拖动条目从所在的容器移到另一个容器中时,就会触发。 Emits when the user removes the item its container by dragging it into another container. |
@Output('cdkDragMoved')
|
当用户拖动条目时触发。慎用,因为此事件将针对用户拖过的每个像素触发。 Emits as the user is dragging the item. Use with caution, because this event will fire for every pixel that the user has dragged. |
@Output('cdkDragReleased')
|
当用户释放了一个拖动条目时触发。位于任何动画开始之前。 Emits when the user has released a drag item, before any animations have started. |
@Output('cdkDragStarted')
|
当用户开始拖动该条目时会触发。 Emits when the user starts dragging the item. |
|
Droppable container that the draggable is a part of. |
|
Element that the draggable is attached to. |
方法
getFreeDragPosition | |
---|---|
获取可拖动对象在投放容器外的像素坐标。 Gets the pixel coordinates of the draggable outside of a drop container. |
|
返回值 Returns |
|
{
readonly x: number;
readonly y: number;
}
|
|
getPlaceholderElement | |
---|---|
返回在拖动当前元素时要用作占位符的元素。 Returns the element that is being used as a placeholder while the current element is being dragged. |
|
返回值 Returns |
|
HTMLElement
|
|
getRootElement | |
---|---|
返回可拖动条目的根元素。 Returns the root draggable element. |
|
返回值 Returns |
|
HTMLElement
|
|
reset | |
---|---|
将一个独立的拖动条目重置到初始位置。 Resets a standalone drag item to its initial position. |
CdkDragHandle
可用于拖动 CdkDrag 实例的手柄。
Handle that can be used to drag a CdkDrag instance.
属性
名称 | 描述 |
---|---|
@Input('cdkDragHandleDisabled')
|
是否要禁用通过该手柄开始拖动的功能。 Whether starting to drag through this handle is disabled. |
|
CdkDragPreview
拖动时将用作预览 CdkDrag 的模板的元素。
Element that will be used as a template for the preview of a CdkDrag when it is being dragged.
属性
名称 | 描述 |
---|---|
@Input()
|
要添加到预览模板实例的上下文数据。 Context data to be added to the preview template instance. |
@Input()
|
预览是否应保持与要拖动的条目相同的大小。 Whether the preview should preserve the same size as the item that is being dragged. |
|
CdkDragPlaceholder
拖动时将用作 CdkDrag 占位符模板的元素。该占位符会用来代替要拖动的元素。
Element that will be used as a template for the placeholder of a CdkDrag when it is being dragged. The placeholder is displayed in place of the element being dragged.
属性
名称 | 描述 |
---|---|
@Input()
|
要添加到占位符模板实例的上下文数据。 Context data to be added to the placeholder template instance. |
|
类
DragRef
可拖动条目的引用。用来操纵或丢弃条目。
Reference to a draggable item. Used to manipulate or dispose of the item.
属性
名称 | 描述 |
---|---|
|
当拖曳序列准备就绪时触发。 Emits as the drag sequence is being prepared. |
|
一个函数,可以用来自定义拖动条目的位置限制逻辑。通过一个包含该用户指针在页面上的当前位置进行调用,并返回一个描述该条目应该渲染在哪个位置的点。 Function that can be used to customize the logic of how the position of the drag item is limited while it's being dragged. Gets called with a point containing the current position of the user's pointer on the page and should return a point describing where the item should be rendered. |
|
可以附加在拖动条目上的任意数据。 Arbitrary data that can be attached to the drag item. |
|
是否已禁止拖动此元素。 Whether starting to drag this element is disabled. |
|
用户在开始拖动元素之前把指针放下之后要等待的毫秒数。 Amount of milliseconds to wait after the user has put their pointer down before starting to drag the element. |
|
当用户把条目放到容器中时,就会触发。 Emits when the user drops the item inside a container. |
|
当用户停止拖动容器中的某个条目时,会发出本通知。 Emits when the user stops dragging an item in the container. |
|
当用户把本条目移到新容器中时发出通知。 Emits when the user has moved the item into a new container. |
|
当用户通过把拖动条目从所在的容器移到另一个容器中时,就会触发。 Emits when the user removes the item its container by dragging it into another container. |
|
拖动时锁定的轴。 Axis along which dragging is locked. |
|
当用户正在拖动该条目时会触发。请谨慎使用,因为此事件会在用户拖动每一个像素时触发。 Emits as the user is dragging the item. Use with caution, because this event will fire for every pixel that the user has dragged. |
|
要添加到预览元素中的类。 Class to be added to the preview element. |
|
当用户释放了一个拖动条目时触发。位于任何动画开始之前。 Emits when the user has released a drag item, before any animations have started. |
|
当用户开始拖动该条目时会触发。 Emits when the user starts dragging the item. |
方法
disableHandle | |
---|---|
禁用拖动手柄。当手柄被禁用时,它会捕获并中止拖动操作。 Sets a handle as disabled. While a handle is disabled, it'll capture and interrupt dragging. |
|
参数 Parameters |
|
handle HTMLElement
|
要被禁用的手柄元素。 Handle element that should be disabled. |
dispose | |
---|---|
从 DOM 元素中移除拖动功能。 Removes the dragging functionality from the DOM element. |
enableHandle | |
---|---|
启用一个已被禁用的手柄。 Enables a handle, if it has been disabled. |
|
参数 Parameters |
|
handle HTMLElement
|
要启用的手柄。 Handle element to be enabled. |
getFreeDragPosition | |
---|---|
获取可拖动元素在投放容器外部的当前位置(以像素为单位)。 Gets the current position in pixels the draggable outside of a drop container. |
|
返回值 Returns |
|
Readonly<Point>
|
|
getPlaceholderElement | |
---|---|
在拖动当前元素的同时,返回当前占位符所在的元素。 Returns the element that is being used as a placeholder while the current element is being dragged. |
|
返回值 Returns |
|
HTMLElement
|
|
getRootElement | |
---|---|
返回可拖动条目的根元素。 Returns the root draggable element. |
|
返回值 Returns |
|
HTMLElement
|
|
getVisibleElement | |
---|---|
获取代表该拖动条目的当前可见元素。拖动期间是其占位符,其它时候是其根元素。 Gets the currently-visible element that represents the drag item. While dragging this is the placeholder, otherwise it's the root element. |
|
返回值 Returns |
|
HTMLElement
|
|
isDragging | |
---|---|
检查当前是否正在拖动该元素。 Checks whether the element is currently being dragged. |
|
返回值 Returns |
|
boolean
|
|
reset | |
---|---|
将一个独立的拖动条目重置到初始位置。 Resets a standalone drag item to its initial position. |
setFreeDragPosition | |
---|---|
设置可拖动元素在投放容器外部的当前位置(以像素为单位)。 Sets the current position in pixels the draggable outside of a drop container. |
|
参数 Parameters |
|
value Point
|
要设置的新位置。 New position to be set. |
返回值 Returns |
|
this
|
|
withBoundaryElement | |
---|---|
用于进行可拖动位置限制的元素。 Element to which the draggable's position will be constrained. |
|
参数 Parameters |
|
boundaryElement HTMLElement | ElementRef<HTMLElement>
|
|
返回值 Returns |
|
this
|
|
withDirection | |
---|---|
设置可拖动条目的布局方向。 Sets the layout direction of the draggable item. |
|
参数 Parameters |
|
direction "ltr" | "rtl"
|
|
返回值 Returns |
|
this
|
|
withHandles | |
---|---|
注册可以用来拖动元素的手柄。 Registers the handles that can be used to drag the element. |
|
参数 Parameters |
|
handles (HTMLElement | ElementRef<HTMLElement>)[]
|
|
返回值 Returns |
|
this
|
|
withPlaceholderTemplate | |
---|---|
注册要用作拖动占位符的模板。 Registers the template that should be used for the drag placeholder. |
|
参数 Parameters |
|
template DragHelperTemplate<any>
|
用来生成占位符的模板。 Template that from which to stamp out the placeholder. |
返回值 Returns |
|
this
|
|
withPreviewTemplate | |
---|---|
注册要用作拖动预览的模板。 Registers the template that should be used for the drag preview. |
|
参数 Parameters |
|
template DragPreviewTemplate<any>
|
用来生成预览图的模板。 Template that from which to stamp out the preview. |
返回值 Returns |
|
this
|
|
withRootElement | |
---|---|
设置备用的拖动根元素。根元素是用户拖动时会被移动的元素。当你尝试在你可能无权访问的元素上启用拖曳时,传入一个备用的根元素是很有用的。 Sets an alternate drag root element. The root element is the element that will be moved as the user is dragging. Passing an alternate root element is useful when trying to enable dragging on an element that you might not have access to. |
|
参数 Parameters |
|
rootElement HTMLElement | ElementRef<HTMLElement>
|
|
返回值 Returns |
|
this
|
|
DropListRef
投放列表的引用。用来操纵或丢弃容器。
Reference to a drop list. Used to manipulate or dispose of the container.
属性
名称 | 描述 |
---|---|
|
当用户把指针移到边缘附近时是否禁止自动滚动视图。 Whether auto-scrolling the view when the user moves their pointer close to the edges is disabled. |
|
当自动滚动元素时,这是每一帧滚动的像素数。 Number of pixels to scroll for each frame when auto-scrolling an element. |
|
在拖动开始之前触发。 Emits right before dragging has started. |
|
任意数据都可以附加到投放列表中。 Arbitrary data that can be attached to the drop list. |
|
是否禁用了从此容器启动拖曳序列的方法。 Whether starting a dragging sequence from this container is disabled. |
|
当用户把一个条目投放进该容器时就会触发。 Emits when the user drops an item inside the container. |
|
投放表附加到的元素 Element that the drop list is attached to. |
|
该函数用于判断是否允许某个条目移入投放容器。 Function that is used to determine whether an item is allowed to be moved into a drop container. |
|
当用户把一个新的拖动条目移到这个容器中时,就会触发。 Emits when the user has moved a new drag item into this container. |
|
当用户把条目拖到另一个容器中并从当前容器中删除该条目时触发。 Emits when the user removes an item from the container by dragging it into another container. |
|
沿着指定的轴锁定容器内可拖动元素的位置。 Locks the position of the draggable elements inside the container along the specified axis. |
|
一个函数,用来判断某个条目是否可以被排序到特定索引。 Functions that is used to determine whether an item can be sorted into a particular index. |
|
当用户正在主动拖动以交换条目时,就会触发。 Emits as the user is swapping items while actively dragging. |
|
是否禁用了列表中的条目排序。 Whether sorting items within the list is disabled. |
方法
connectedTo | |
---|---|
设置连接到这个容器的容器。当有两个或多个容器相连时,系统会允许用户在它们之间传输条目。 Sets the containers that are connected to this one. When two or more containers are connected, the user will be allowed to transfer items between them. |
|
参数 Parameters |
|
connectedTo DropListRef<any>[]
|
当前容器应该连接到的其他容器。 Other containers that the current containers should be connected to. |
返回值 Returns |
|
this
|
|
dispose | |
---|---|
从 DOM 元素中移除投放列表的功能。 Removes the drop list functionality from the DOM element. |
drop | |
---|---|
把条目投放到这个容器里 Drops an item into this container. |
|
参数 Parameters |
|
item DragRefInternal
|
要被投放进此容器的条目。 Item being dropped into the container. |
currentIndex number
|
该条目应该插入到的索引。 Index at which the item should be inserted. |
previousIndex number
|
拖动开始时该条目的索引。 Index of the item when dragging started. |
previousContainer DropListRef<any>
|
该条目被拖入的容器。 Container from which the item got dragged in. |
isPointerOverContainer boolean
|
当条目被删除时,用户的指针是否在此容器上。 Whether the user's pointer was over the container when the item was dropped. |
distance Point
|
自拖曳序列开始以来用户拖动过的距离。 Distance the user has dragged since the start of the dragging sequence. |
enter | |
---|---|
发出一个事件,表明用户已经把某个条目移到了容器中。 Emits an event to indicate that the user moved an item into the container. |
|
参数 Parameters |
|
item DragRefInternal
|
被移入容器中的条目。 Item that was moved into the container. |
pointerX number
|
该条目沿 X 轴的位置。 Position of the item along the X axis. |
pointerY number
|
该条目沿 Y 轴的位置。 Position of the item along the Y axis. |
index? number
|
条目进来后的索引。如果省略,容器会自动尝试定位。 Index at which the item entered. If omitted, the container will try to figure it out automatically. |
exit | |
---|---|
用户将一个条目拖入另一个容器并从当前容器删除该条目。 Removes an item from the container after it was dragged into another container by the user. |
|
参数 Parameters |
|
item DragRefInternal
|
被拖走的条目 Item that was dragged out. |
getItemIndex | |
---|---|
找出容器中某个条目的索引。 Figures out the index of an item in the container. |
|
参数 Parameters |
|
item DragRefInternal
|
应该确定索引的条目。 Item whose index should be determined. |
返回值 Returns |
|
number
|
|
getScrollableParents | |
---|---|
获取在这个投放容器中注册的可滚动父类。 Gets the scrollable parents that are registered with this drop container. |
|
返回值 Returns |
|
ReadonlyArray<HTMLElement>
|
|
isDragging | |
---|---|
当前是否正在拖动此列表中的某个条目。 Whether an item from this list is currently being dragged. |
isReceiving | |
---|---|
列表是否能够接收当前被拖入的已连接投放列表中的条目。 Whether the list is able to receive the item that is currently being dragged inside a connected drop list. |
|
返回值 Returns |
|
boolean
|
|
start | |
---|---|
开始拖动一个条目。 Starts dragging an item. |
withDirection | |
---|---|
设置投放列表的布局方向。 Sets the layout direction of the drop list. |
|
参数 Parameters |
|
direction "ltr" | "rtl"
|
|
返回值 Returns |
|
this
|
|
withItems | |
---|---|
设置属于该列表的可拖动条目。 Sets the draggable items that are a part of this list. |
|
参数 Parameters |
|
items DragRefInternal[]
|
属于这个列表的条目。 Items that are a part of this list. |
返回值 Returns |
|
this
|
|
withOrientation | |
---|---|
设置容器的方向。 Sets the orientation of the container. |
|
参数 Parameters |
|
orientation "vertical" | "horizontal"
|
容器的新方向。 New orientation for the container. |
返回值 Returns |
|
this
|
|
withScrollableParents | |
---|---|
当用户在拖动时,设置哪些父元素可以滚动。 Sets which parent elements are can be scrolled while the user is dragging. |
|
参数 Parameters |
|
elements HTMLElement[]
|
那些可以滚动的元素。 Elements that can be scrolled. |
返回值 Returns |
|
this
|
|
接口
DragRefConfig
可以用来配置 DragRef 行为的对象。
Object that can be used to configure the behavior of DragRef.
属性
名称 | 描述 |
---|---|
|
在 CDK 启动拖曳序列之前,用户应该拖动的最小像素数。 Minimum amount of pixels that the user should drag, before the CDK initiates a drag sequence. |
|
当前拖动条目所嵌套在的父拖动的引用。 Ref that the current drag item is nested in. |
|
在 CDK 认为改变了拖动方向之前,用户应该拖动的像素数量。 Amount the pixels the user should drag before the CDK considers them to have changed the drag direction. |
|
|
Point
页面上或元素中的点坐标。
Point on the page or within an element.
属性
名称 | 描述 |
---|---|
|
|
|
CdkDragStart
当用户开始拖动拖动时会发出本事件。
Event emitted when the user starts dragging a draggable.
属性
名称 | 描述 |
---|---|
|
发出了本事件的可拖动对象。 Draggable that emitted the event. |
CdkDragRelease
用户在释放条目时发出的事件,发生在开始任何动画之前。
Event emitted when the user releases an item, before any animations have started.
属性
名称 | 描述 |
---|---|
|
发出了本事件的可拖动对象。 Draggable that emitted the event. |
CdkDragEnd
当用户停止拖动时会发出本事件。
Event emitted when the user stops dragging a draggable.
属性
名称 | 描述 |
---|---|
|
自拖曳序列启动以来用户拖动过的像素距离。 Distance in pixels that the user has dragged since the drag sequence started. |
|
发出了本事件的可拖动对象。 Draggable that emitted the event. |
CdkDragEnter
当用户把条目移到新的投送容器中时,就会发出本事件。
Event emitted when the user moves an item into a new drop container.
属性
名称 | 描述 |
---|---|
|
用户移入了该条目的容器。 Container into which the user has moved the item. |
|
该条目已进入该容器中的索引。 Index at which the item has entered the container. |
|
被移入容器中的条目。 Item that was moved into the container. |
CdkDragExit
当用户把一个条目移到另一个投放容器,并从当前容器中移除时,就会触发本事件。
Event emitted when the user removes an item from a drop container by moving it into another one.
属性
名称 | 描述 |
---|---|
|
用户已移除本条目的容器。 Container from which the user has a removed an item. |
|
已从容器中移除的条目 Item that was removed from the container. |
CdkDragDrop
当用户在投送容器中放入一个可拖动条目时,就会发出本事件。
Event emitted when the user drops a draggable item inside a drop container.
属性
名称 | 描述 |
---|---|
|
该条目投送到的容器。 Container in which the item was dropped. |
|
此条目的当前索引。 Current index of the item. |
|
自拖曳序列启动以来用户拖动的像素距离。 Distance in pixels that the user has dragged since the drag sequence started. |
|
当条目被移除时,用户的指针是否还在容器上。 Whether the user's pointer was over the container when the item was dropped. |
|
被投放的条目 Item that is being dropped. |
|
从中拿出条目的容器。可以和 Container from which the item was picked up. Can be the same as the |
|
该条目被拿起时的条目索引。 Index of the item when it was picked up. |
CdkDragMove
当用户正在拖动一个条目时,就会发出一个事件。
Event emitted as the user is dragging a draggable item.
属性
名称 | 描述 |
---|---|
|
指示用户沿每个轴拖动元素的方向。 Indicates the direction in which the user is dragging the element along each axis.
|
|
自拖曳序列启动以来用户已拖动的像素距离。 Distance in pixels that the user has dragged since the drag sequence started. |
|
导致拖曳的原生事件 Native event that is causing the dragging. |
|
用户指针在页面上的位置。 Position of the user's pointer on the page. |
|
被拖动的条目 Item that is being dragged. |
CdkDragSortEvent
当用户交换两个拖动条目的位置时,会发出一个事件。
Event emitted when the user swaps the position of two drag items.
属性
名称 | 描述 |
---|---|
|
该条目所属的容器。 Container that the item belongs to. |
|
该条目在当前排序中的索引 Index that the item is currently in. |
|
正在排序的条目 Item that is being sorted. |
|
该条目在先前排序中的索引。 Index from which the item was sorted previously. |
DragDropConfig
可用于配置模块或组件中的拖动条目和拖放列表的对象。
Object that can be used to configure the drag items and drop lists within a module or a component.
属性
名称 | 描述 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
函数
moveItemInArray | |
---|---|
把某个条目从数组中的一个索引号移到另一个索引号。 Moves an item one index in an array to another. |
|
参数 Parameters |
|
array T[]
|
要移动此条目的数组。 Array in which to move the item. |
fromIndex number
|
此条目的起始索引。 Starting index of the item. |
toIndex number
|
此条目应该移到的索引。 Index to which the item should be moved. |
transferArrayItem | |
---|---|
把一个条目从一个数组移动到另一个数组。 Moves an item from one array to another. |
|
参数 Parameters |
|
currentArray T[]
|
要从中传输该条目的数组。 Array from which to transfer the item. |
targetArray T[]
|
要放入该条目的数组。 Array into which to put the item. |
currentIndex number
|
当前数组中该条目的索引。 Index of the item in its current array. |
targetIndex number
|
该条目要插入到的索引。 Index at which to insert the item. |
copyArrayItem | |
---|---|
将一个条目从一个数组复制到另一个数组,并把它放在当前数组的原始位置。 Copies an item from one array to another, leaving it in its original position in current array. |
|
参数 Parameters |
|
currentArray T[]
|
要从中复制条目的数组。 Array from which to copy the item. |
targetArray T[]
|
要把该条目复制到的数组。 Array into which is copy the item. |
currentIndex number
|
该条目在当前数组中的索引。 Index of the item in its current array. |
targetIndex number
|
该条目在目标数组中要插入的索引。 Index at which to insert the item. |
类型别名
DragStartDelay
可用于配置拖动开始延迟的可能值。
Possible values that can be used to configure the drag start delay.
type DragStartDelay = number | {
touch: number;
mouse: number;
};
DragAxis
可以锁定可能的拖动轴。
Possible axis along which dragging can be locked.
type DragAxis = 'x' | 'y';
DragConstrainPosition
可用于约束元素拖动位置的函数。
Function that can be used to constrain the position of a dragged element.
type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point;
DropListOrientation
下拉列表的可能方向。
Possible orientations for a drop list.
type DropListOrientation = 'horizontal' | 'vertical';
常量
CDK_DROP_LIST
用来引用 CdkDropList
实例的注入令牌。它用作实际 CdkDropList
类的备用令牌,这可能导致不必要地保留该类及其指令元数据。
Injection token that can be used to reference instances of CdkDropList
. It serves as
alternative token to the actual CdkDropList
class which could cause unnecessary
retention of the class and its directive metadata.
const CDK_DROP_LIST: InjectionToken<CdkDropList<any>>;
CDK_DRAG_CONFIG
注入令牌,可用于配置与拖放相关的组件的行为。
Injection token that can be used to configure the behavior of the drag&drop-related components.
const CDK_DRAG_CONFIG: InjectionToken<DragDropConfig>;
CDK_DROP_LIST_GROUP
用来引用 CdkDropListGroup
实例的注入令牌。它用作实际 CdkDropListGroup
类的备用令牌,直接使用该类可能导致该类及其指令的元数据无法被优化掉。
Injection token that can be used to reference instances of CdkDropListGroup
. It serves as
alternative token to the actual CdkDropListGroup
class which could cause unnecessary
retention of the class and its directive metadata.
const CDK_DROP_LIST_GROUP: InjectionToken<CdkDropListGroup<unknown>>;
CDK_DRAG_HANDLE
用来引用 CdkDragHandle
实例的注入令牌。它用作实际 CdkDragHandle
类的备用令牌,直接使用该类可能导致该类及其指令的元数据无法被优化掉。
Injection token that can be used to reference instances of CdkDragHandle
. It serves as
alternative token to the actual CdkDragHandle
class which could cause unnecessary
retention of the class and its directive metadata.
const CDK_DRAG_HANDLE: InjectionToken<CdkDragHandle>;
CDK_DRAG_PREVIEW
用来引用 CdkDragPreview
实例的注入令牌。它用作实际 CdkDragPreview
类的备用令牌,直接使用该类可能导致该类及其指令的元数据无法被优化掉。
Injection token that can be used to reference instances of CdkDragPreview
. It serves as
alternative token to the actual CdkDragPreview
class which could cause unnecessary
retention of the class and its directive metadata.
const CDK_DRAG_PREVIEW: InjectionToken<CdkDragPreview<any>>;
CDK_DRAG_PLACEHOLDER
用来引用 CdkDragPlaceholder
实例的注入令牌。它用作实际 CdkDragPlaceholder
类的备用令牌,直接使用该类可能导致该类及其指令的元数据无法被优化掉。
Injection token that can be used to reference instances of CdkDragPlaceholder
. It serves as
alternative token to the actual CdkDragPlaceholder
class which could cause unnecessary
retention of the class and its directive metadata.
const CDK_DRAG_PLACEHOLDER: InjectionToken<CdkDragPlaceholder<any>>;