Syncs the inputs of the CdkDrag with the options of the underlying DragRef.
(ref: DragRef<CdkDrag<T>>)
| 421 | |
| 422 | /** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */ |
| 423 | private _syncInputs(ref: DragRef<CdkDrag<T>>) { |
| 424 | ref.beforeStarted.subscribe(() => { |
| 425 | if (!ref.isDragging()) { |
| 426 | const dir = this._dir; |
| 427 | const dragStartDelay = this.dragStartDelay; |
| 428 | const placeholder = this._placeholderTemplate |
| 429 | ? { |
| 430 | template: this._placeholderTemplate.templateRef, |
| 431 | context: this._placeholderTemplate.data, |
| 432 | viewContainer: this._viewContainerRef, |
| 433 | } |
| 434 | : null; |
| 435 | const preview = this._previewTemplate |
| 436 | ? { |
| 437 | template: this._previewTemplate.templateRef, |
| 438 | context: this._previewTemplate.data, |
| 439 | matchSize: this._previewTemplate.matchSize, |
| 440 | viewContainer: this._viewContainerRef, |
| 441 | } |
| 442 | : null; |
| 443 | |
| 444 | ref.disabled = this.disabled; |
| 445 | ref.lockAxis = this.lockAxis; |
| 446 | ref.scale = this.scale; |
| 447 | ref.dragStartDelay = |
| 448 | typeof dragStartDelay === 'object' && dragStartDelay |
| 449 | ? dragStartDelay |
| 450 | : coerceNumberProperty(dragStartDelay); |
| 451 | ref.constrainPosition = this.constrainPosition; |
| 452 | ref.previewClass = this.previewClass; |
| 453 | ref |
| 454 | .withBoundaryElement(this._getBoundaryElement()) |
| 455 | .withPlaceholderTemplate(placeholder) |
| 456 | .withPreviewTemplate(preview) |
| 457 | .withPreviewContainer(this.previewContainer || 'global'); |
| 458 | |
| 459 | if (dir) { |
| 460 | ref.withDirection(dir.value); |
| 461 | } |
| 462 | } |
| 463 | }); |
| 464 | |
| 465 | // This only needs to be resolved once. |
| 466 | ref.beforeStarted.pipe(take(1)).subscribe(() => { |
| 467 | // If we managed to resolve a parent through DI, use it. |
| 468 | if (this._parentDrag) { |
| 469 | ref.withParent(this._parentDrag._dragRef); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | // Otherwise fall back to resolving the parent by looking up the DOM. This can happen if |
| 474 | // the item was projected into another item by something like `ngTemplateOutlet`. |
| 475 | let parent = this.element.nativeElement.parentElement; |
| 476 | while (parent) { |
| 477 | const parentDrag = this._dragDropRegistry.getDragDirectiveForNode(parent); |
| 478 | if (parentDrag) { |
| 479 | ref.withParent(parentDrag._dragRef); |
| 480 | break; |
no test coverage detected