I am using a palette and a diagram with Angular. Both are having their own model as below:
Palette Model Template
palette.nodeTemplateMap.add(‘Question’,
$(go.Node, 'vertical', nodeStyle(),
$(go.Panel, 'Auto',
$(go.Shape, 'Rectangle',
{
width: 55,
height: 30,
stroke: null
},
new go.Binding('fill', 'color')
),
$(go.TextBlock, { margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit },
new go.Binding('text')))
));
Diagram Model Template:
dia.nodeTemplateMap.add(‘Question’,
$(go.Node, 'vertical', nodeStyle(),
$(go.Panel, 'Spot',
$(go.Shape, 'Rectangle',
{
width: 100,
height: 40,
stroke: null
},
new go.Binding('fill', 'color')
),
$(go.TextBlock, { margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: true },
new go.Binding('text').makeTwoWay()),
// Ports
makePort('t', go.Spot.TopCenter, true, true),
makePort('l', go.Spot.LeftCenter, true, true),
makePort('r', go.Spot.RightCenter, true, true),
makePort('b', go.Spot.BottomCenter, true, true)
)));
and below is initial Palette NodeData for Question:
{ text: ‘Question’, category: ‘Question’, color: ‘#85C1E9’, data:
{ questionText: ' ',
placeholder: 'Enter question text',
answerType: [
{type: 'SingleOption', isSelected: false},
{type: 'MultipleOptions', isSelected: false},
{type: 'SingleLineText', isSelected: false},
{type: 'MultiLineText', isSelected: false},
{type: 'Date', isSelected: false}
],
helpUrl: ' ',
isMandatoryAnswer: true,
displayText: ' ' } }
Now as you can see here that Node is having custom data property which I am using to show as a popup data once I drag the node from the Palette to Diagram. The issue which I am facing here is when I am updating one of the properties inside the node’s data object say(questionText) it’s getting replicated in other nodes as well if there is any same node present in the diagram.
Below is the drag event which I am using inside ngAfterViewInit():
this.myDiagramComponent.diagram.addDiagramListener(‘ChangedSelection’, function(e) {
if (e.diagram.selection.count === 0) {
appComp.selectedNode = null; // or this.selectedNode = null;
}
const node = e.diagram.selection.first();
if (node instanceof go.Node) {
appComp.selectedNode = node; // or this.selectedNode = node;
}
});
Below is sample HTML code which I am using to bind data on popup and this is poping up once I am clicking a node:
<fieldset>
<legend>Basic</legend>
Question Text
<bt-inputtext [(ngModel)]="selectedNode?.data.data.questionText" placeholder="Enter question text"></bt-inputtext>
Issues I am facing with this way are:
-
Once I update any item(say questionText) for one of the node it is getting updated for all of the nodes even though boh the nodes are having unique key with them.
-
Have seen that palette nodeData is getting updated as well if I am updating any of the field of data property inside a node in my diagram.
Is two way binding is an issue here? Or I am missing something. If copyNodeDataFucntion is an option here please suggest how to add this function in angular(didn’t get proper reference).