Articles in this section
Category / Section

How to Create Custom Shapes Using Template Binding in Angular Diagram?

2 mins read

The Syncfusion® Angular Diagram supports rendering custom HTML content within nodes using template binding. This allows you to create nodes with dynamic HTML elements such as buttons, forms, or other content.

To define a node with custom HTML content, set the shape property of the node to HTML. Specify the template content using the nodeTemplate function. Here’s how:

export class AppComponent {
 @ViewChild('diagram')
 public diagram?: DiagramComponent;
 public nodes: NodeModel[] = [
   {
     id: 'node1',
     offsetX: 100,
     offsetY: 100,
     width: 100,
     height: 100
   },
 ];
 public getNodeDefaults(obj: NodeModel, diagram: Diagram): NodeModel {
   obj.shape = { type: 'HTML'};
   obj.backgroundColor = '#6BA5D7';
   return obj;
 }
} 

Define the Custom HTML Template:

Use an Angular ng-template to define the custom HTML structure inside a node.

template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px" [nodes]="nodes" [getNodeDefaults]="getNodeDefaults">
// Define the node template
<ng-template #nodeTemplate let-data>
  <ng-container>
     <div>
      <button (click)="onNodeButtonClick($event)">Button</button>
    </div>
  </ng-container>
</ng-template> 
</ejs-diagram>`, 

Sample: Click Here

Conclusion
I hope you enjoyed about how to create custom shapes using template binding 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, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied