0

I'm trying to remove an existing connection(DragConnectionCreatePolicy) between two nodes. I tried two ways, the first using this command:

this.canvas.remove(connection) but it returns this: EXCEPTION: figure.getCanvas is not a function

The second one

var cmd =  new draw2d.CommandDelete(connection);
this.canvas.getCommandStack().execute(cmd)

instead returns EXCEPTION: draw2d.CommandDelete is not a constructor

What am I mistaking?

I'm using draw2d inside an Angular 2 component.

export class sampleDraw implements OnInit {


  canvas:any;

  createGraph() {

    this.canvas = new draw2d.Canvas("canvas-div");

}

ngOnInit(){
    this.createGraph()

  }
}
uroti
  • 147
  • 1
  • 11
  • I noticed if I put like parameter an object figure.class the method this.canvas.remove(figure) works, if I put n object connection.class doesn't work. – uroti Aug 10 '17 at 20:15

1 Answers1

0

There is code which you want in draw2d libray. I think you can remove the connection that already connected like this:

this.canvas.lines.remove(connection);
connection.setCanvas(null);
connection.disconnect();

UPDATE:

I found a way to remove any items in draw2d. Please define the command to delete the item. And execute it.

let cmd = connection.createCommand(new draw2d.command.CommandType(draw2d.command.CommandType.DELETE));
if (cmd !== null) {                     
    connection.getCanvas().getCommandStack().execute(cmd);
}