1

I have an issue when using Angular5/6 with Jquery UI draggable.

I have a model (an array) and a draggable item using JQueryUI draggable, whenever I stop dragging the item, a new element will be pushed to the model. However, after I drag the item to somewhere else, although a new element has already added to the model, the view is still not updated, I have to click on the draggable item again to trigger the view to update.

Do you have any suggestions for this issue?

Here is my code:

export class App {
  model: any;

  constructor() {
    this.model = [{name: "Item 1"}, {name: "Item 2"}];
  }

  ngAfterViewInit() {
      this.initDraggable();
  }   

  initDraggable($content) : void {
    var me = this;
    var options = {
          helper: "clone",
          start: function () {
              console.log("start dragging");
          },
          stop: function () {
            console.log("stop dragging - add new element to the model");
            me.model.push({
                name: "New Item"
            });
          }
      };

     $(".draggable-item").draggable(options);
  }
}

Here is my plunker: https://plnkr.co/edit/tZbLHy0tYHd81nOupJVU

Thanks!

ThuyNguyen
  • 1,127
  • 3
  • 14
  • 24
  • Possible duplicate of [AngularJS : ng-model binding not updating when changed with jQuery](https://stackoverflow.com/questions/11873627/angularjs-ng-model-binding-not-updating-when-changed-with-jquery) – blgt Jul 12 '18 at 09:10
  • Hi @blgt `AngularJS : ng-model binding not updating when changed with jQuery` is the question for Angular1.x, and my question for angular5.x,6.x – ThuyNguyen Jul 12 '18 at 10:13

0 Answers0