moveable icon indicating copy to clipboard operation
moveable copied to clipboard

Dynamically adding Moveables not working

Open javanese84 opened this issue 2 years ago • 2 comments

Environments

  • Framework name: Angular
  • Framework version: ^0.49.0

Description

I am not able to dynamically add a new Moveable. I have 3 Moveables initially which are working and call the following function to add a new one, which is displayed but NOT working (not draggable, nor resizable).

HTML markup:

<div class="container" id="container" #container>
  <img class="target w-20" src="assets/sticker/tractor.png" />
  <img class="target w-20" src="assets/sticker/tractor.png" />
  <img class="target w-20" src="assets/sticker/tractor.png" />
  <ngx-moveable
              #moveable
              [target]="'.target'"
              [hideDefaultLines]="true"
              [individualGroupable]="true"
              [draggable]="true"
              [throttleDrag]="throttleDrag"
              [edgeDraggable]="false"
              [startDragRotate]="startDragRotate"
              [throttleDragRotate]="throttleDragRotate"
              [scalable]="scalable"
              [keepRatio]="keepRatio"
              [throttleScale]="throttleScale"
              [renderDirections]="renderDirections"
              [rotatable]="rotatable"
              [throttleRotate]="throttleRotate"
              [rotationPosition]="rotationPosition"
              (drag)="onDrag($event)"
              (scale)="onScale($event)"
              (rotate)="onRotate($event)"
 ></ngx-moveable>
</div>

function in component.ts

async addSticker(sticker: Sticker) {
    const container = document.getElementById('container');
    if (container) {
      let img = document.createElement('img');
      img.className = 'target w-20';
      img.src = sticker.asset
      container.appendChild(img);
      // await this.moveable.updateRect();
      this.moveable.updateSelectors(); 
    }
  }

javanese84 avatar Nov 24 '23 16:11 javanese84

@javanese84

Dragging a group requires dragGroup, scaleGroup, and rotateGroup.

https://daybrush.com/moveable/storybook/?path=/story/group--group-draggable-scalable-rotatable

daybrush avatar Dec 01 '23 16:12 daybrush

@daybrush thanks for your answer, but that doesn't solve my issue when dynamically adding another item to the group. The added item is not recognized by the moveable component and so does not work. Can maybe provide an example of dynamically adding a item to the moveable component?

javanese84 avatar Dec 06 '23 19:12 javanese84