Hi!
I’m using Angular and gojs-angular. In my application I need to fully replace diagram model, but after this operation new nodes (dropped from palette, copied and pasted, added programatically) are added twice.
Here is a demo which replicates the issue: GitHub - Hazzed5/gojs-model-change-issue
In the ngAfterViewInit()
function changeModel()
is called:
changeModel() {
this.graphNodeData = [];
this.graphLinkData = [];
const model = new go.GraphLinksModel(
this.graphNodeData,
this.graphLinkData
);
model.linkToPortIdProperty = "toPort";
model.linkFromPortIdProperty = "fromPort";
model.linkKeyProperty = "key";
model.nodeKeyProperty = "key";
model.nodeCategoryProperty = "category";
this.graphComponent.diagram.model = model;
this.exampleMessagesArray.forEach((message) => {
this.graphNodeData.push(message);
});
}
Even though this.exampleMessagesArray
contains 4 elements, this.graphNodeData
and model.nodeDataArray
have 8 elements with duplicated keys.
How can I fix this problem?