Trying to remove a link

I am trying to remove a link from a node (TreeNode) which is nested inside a groupTemplate. My aim is to revert a dragging action (from a node to another) or the delete action of a link. At the moment, just to give you some hints, I am working on AngularJS declaring both GraphLinksModel arrays in the “controller.js” as below:

item = 4;
for(i=0; i< items; i++){
   ....
   nodeDataArray.push({ isGroup: true, key: -i-1, text: "Board "+(i+1), color: "lightblue", fig: "RoundedRectangle", xy: x+" "+y });
}
...
linkDataArray.push({ key: 10000, from: 1000, to: 0, category: "Mapping", fromNode: "Board 2", toNode: "Board 1" });

$scope.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
$scope.model.linkFromPortIdProperty = "fromNode";
$scope.model.linkToPortIdProperty = "toNode";

while in the “directory.js” (which has the logic of the GraphLinksModel actions) i added the following:

myDiagram = $(go.Diagram, element[0],
{
   ...
   "undoManager.isEnabled": false,
   "ModelChanged": function(evt) {
      if (evt.isTransactionFinished){
         if(evt.as == "Initial Layout") document.getElementById("mySavedModel").value = evt.model.toJson();
         else if(evt.as == "Delete" || evt.as == "Linking"){
            ...
            old_linkarray = go.Model.fromJson(document.getElementById("mySavedModel").value).linkDataArray;
            new_linkarray = evt.model.linkDataArray;
            result = model_links_diff(old_linkarray, new_linkarray); //it returns some info and the difference (json object) between the old model and the new one (both saved in a div)
            if(result.revert){
               if(result.action == "mount"){
                  console.log("REVERT MOUNT");

                  myDiagram.startTransaction("mount action not allowed");
                  //AT THIS POINT: --> result.link = { key: 10000, from: 1000, to: 0, category: "Mapping", fromNode: "Board 2", toNode: "Board 1" };
                  myDiagram.model.removeLinkData(result.link);
                  myDiagram.commitTransaction("mount action not allowed");
                  ...

So at this point I can do the addLinkData (not pasted here) transaction and it works but not the removeLinkData. What am I missing?

Thanks in advance…

If there is no transaction under way, can you just CommandHandler.undo()?

If there is a transaction ongoing, can you just call rollbackTransaction?

Or is there some other requirement that I am not understanding from your description?

Enabling undoManger.isEnabled=true in order to use the myDiagram.commandHandler.undo() function forced me to catch also the undo action (CTRL+Z) to update the model accordingly. I also inserted some other check functions to make everything work as I expected. Now everything is fine. Thanks