Update diagram json before loading a diagram in Angular.
This article explains how to update diagram json before loading a diagram in angular. To update the diagram json before loading Angular Diagram.
Follow the steps below:
- After rendering the diagram, save the initial diagram data in a separate variable.
app.component.html
<input type="button" id="save" (click)="Save()" value="Save" />
app.component.ts
public local: string;
public Save() {
this.local = this.diagram.saveDiagram();
}
- After saving the diagram data, parse the saved data to convert it into an object. This allows you to manipulate the nodes and connectors in the diagram. For example, you can change the fill property for nodes.
app.component.html
<input type="button" id="load" (click)="Load()" value="Load" />
app.component.ts
public Load() {
this.diagramData = JSON.parse(this.local);
for (let i: number = 0; i < this.diagramData.nodes.length; i++) {
(this.diagramData as any).nodes[i].style.fill = 'red';
}
}
- Once you’ve made the necessary changes to the diagram data, stringify the modified data and pass it to the loadDiagram method. This method will load the updated diagram from the serialized string data.
app.component.ts
public Load() {
this.diagramData = JSON.parse(this.local);
for (let i: number = 0; i < this.diagramData.nodes.length; i++) {
(this.diagramData as any).nodes[i].style.fill = 'red';
}
this.diagram.loadDiagram(JSON.stringify(this.diagramData));
}
Refer to the working sample for additional details and implementation:Sample
Conclusion
We hope you enjoyed learning about how to update diagram JSON before loading a diagram in Angular.
You can refer to our Angular Diagram feature tour page to learn about its other groundbreaking feature representations and documentation to quickly get started with configuration specifications. You can also explore our Angular Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!