Nonse
Nonse

Reputation: 1

Angular, Drag and Drop, change text while dragging element

How to change text of draggable element, while dragging, I have snippet from cdk/drag-and-drop library. It gives parameter to catch event while, dragging. I can change via native element, but it changes all styles, and also I need to set another event on dragover or other actions. What are the options, If I want put random text on dragging element?

In Html

(cdkDragStarted)="dragStarted($event)"  

In TS

dragStarted(event) {  
    event.source.element.nativeElement.textContent = '1212';
  }

Upvotes: 0

Views: 2232

Answers (2)

iamaword
iamaword

Reputation: 1499

I'm not 100% sure, but I know renderer2 is the recommended way to deal with template interaction from the ts file. Perhaps in the drag method try modifying the text using renderer2. If it's not changing correctly still, my next step would be doing some manual change detection in the dragStarted method. If you want it temporarily changed while being dragged, muravev's response has you covered.

Upvotes: 0

muravev
muravev

Reputation: 76

If you want to put random text on dragging element, you should use *cdkDragPreview

Upvotes: 1

Related Questions