angular2-draggable icon indicating copy to clipboard operation
angular2-draggable copied to clipboard

how to set 'position' value dynamically

Open Atercatus opened this issue 7 years ago • 8 comments

this directive is awesome. i wanna know that how to set the position value dynamically. thanks

Atercatus avatar Apr 29 '18 08:04 Atercatus

You can use the input position in the element. It says that it sets the initial position but it can actually control the current position. An example is this

<div ngDraggable class="drag-block"[position]="{x: objectVar?.x, y:objectVar?.y}">

spanagiot avatar May 02 '18 13:05 spanagiot

if i set the value, element moves twice

Atercatus avatar May 11 '18 10:05 Atercatus

What do you mean it moves twice? Can you paste an example code to have a closer look?

spanagiot avatar May 11 '18 10:05 spanagiot

oh it's solved. this is active this.position = P1;

but this is not active this.position.x = P1.x; this.position.y = P1.y;

Atercatus avatar May 11 '18 12:05 Atercatus

I recommend having x,y properties in your object and use them like in the example earlier. This made things much easier for me to manipulate the position of the objects I wanted precisely. I'm glad that it's solved

spanagiot avatar May 11 '18 12:05 spanagiot

thanks. it's very helpful for me

Atercatus avatar May 11 '18 12:05 Atercatus

hello image i have a problem with the position if i add dynamically a new draggable element, the position of the old elements change(in my exemple the element 1 "pompe 1" move automatically to behind when i add a new element and if i add 2 element with the same position e.g {x:0,y:0}, they dot not show in the same place in the img the there are 3 element that's have the same position but they are placed in different places ps: sorry for my bad english

roufa95 avatar Aug 01 '18 17:08 roufa95

Can you post your code? Because I try to recreate it and I can't. I tried creating 2 elements on the same place and they overlap normally. Maybe you have them as a grid? This is how it looks and it would make sense for not allowing more than 1 element in a specific position.

spanagiot avatar Aug 09 '18 09:08 spanagiot