How to bind click event to HTML button node using Angular Diagram?
First, create an HTML node with a button. In the Angular Diagram, a button for each HTML node must be provided either as a string content or an ng-template to trigger the click event. Below is a code snippet demonstrating how to render the button using an ng-template
:
app.component.html
<div class="content-wrapper">
<ejs-diagram
#diagram
id="diagram"
width="100%"
height="700px"
[nodes]="nodes"
>
<ng-template #nodeTemplate let-data>
<ng-container>
<div
style="width:85px;height:85px;background:blue"
>
<button>Click me</button>
</div>
</ng-container>
</ng-template>
</ejs-diagram>
</div>
app.component.ts
public nodes: NodeModel[] = [
{
id: 'node1',
width: 80,
height: 80,
offsetX: 200,
offsetY: 300,
shape: {
type: 'HTML',
},
style: {
strokeColor: 'black',
strokeWidth: 2,
},
},
];
To trigger the click event on the button, add the click event inside the button div element. In the below sample, we have bound the click event and changed the shape to basic, and filled the node color.
app.component.html
<ng-template #nodeTemplate let-data>
<ng-container>
<div
style="width:85px;height:85px;background:blue"
(click)="button()"
>
<button>Click me</button>
</div>
</ng-container>
</ng-template>
app.component.ts
//Method to trigger on clicking the button
public button() {
this.diagram.nodes[0].shape = { type: 'Basic' };
this.diagram.nodes[0].style = { fill: 'red' };
this.diagram.dataBind();
}
Conclusion
I hope you enjoyed learning about how to bind click event to HTML button node using 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, Direct-Trac, or feedback portal. We are always happy to assist you!