How to create and update annotation template dynamically in Angular Diagram
This article explains how to create and update annotation template dynamically in Angular Diagram. In Angular Diagram, Annotation is a block of text that can be displayed over a node or connector. Annotation is used to textually represent an object with a string that can be edited at runtime. Diagram provides either an HTML or SVG template to node and connector annotations. To do this, simply access the annotation template property and specify the desired template. The template should be in a string format. To see an example of how to set an annotation template for a node and connector.
Refer to the code snippet below:
//initilaize the diagram
<ejs-diagram #diagram id="diagram" width="100%" height="780px"
[nodes]="nodes" [connectors]="connectors" > </ejs-diagram>
//initilaize the nodes and connectors
public nodes: NodeModel[] = [
{
id: 'node1',
width: 100,
height: 100,
offsetX: 100,
offsetY: 100,
annotations:[ {
content: '|||',
template:
'<div><img src = "https://www.freepnglogos.com/uploads/plus-icon/plus-icon-plus-math-icon-download-icons-9.png" height = "30" weight = "30"/></div>',
},]
}, ]
public connectors: ConnectorModel[] = [
{
id: 'connector4',
sourcePoint: { x: 250, y: 400 },
targetPoint: { x: 400, y: 400 },
annotations: [
{
content: 'F',
offset: 1,
margin: { bottom: 20 },
template: '<div><input type="button" value="Submit"></div>',
},
{
offset: 0.5,
content: 'HTML Template',
margin: { top: 20 },
}
],
},
];
Additionally, annotation templates can be changed dynamically in response to user actions. The code snippet below illustrates how to update the annotation template for a node and a connector on a button click:
<button (click)="updateTemplate()">Update template</button>
public updateTemplate () {
// Set the annotation template for node and connector annotation this.diagram.connectors[0].annotations[0].template = '<div><input type="button" value="hello"></div>';// To reflect the changes in diagram this.diagram.dataBind(); }this.diagram.nodes[0].annotations[0].template = '<div><input type="button" value="Button"></div>';
This code dynamically changes the annotation templates for a node and a connector, followed by updating the diagram to reflect the changes.
Refer to the working sample for additional details and implementation: sample
Conclusion
We hope you enjoyed learning how to create and update annotation template dynamically in Angular Diagram.
You can refer to our Angular Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for 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 check out 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!