How To change HTML content into HTML Template in drop event
This article explains how to change HTML content into an HTML template in a drop event.We don’t have direct support to render HTML template nodes in the symbol palette.
However, we can render HTML content nodes inside the symbol palette.
Refer to the code below to render HTML content nodes inside the palette:
public palettes: PaletteModel[] = [
{
id: 'flow',
expanded: true,
title: 'HTML Shapes',
symbols: [
{
id: 'node1',
shape: {
type: 'HTML',
content:
'<div className="test" style="width:100%"><input type="button" id="button" value=Button></div>'
},
},
{
id: 'node2',
shape: {
type: 'HTML',
content:
'<div ><input type="test" style="width:100%" id="string" value=Input></div>'
},
},
],
},
];
After rendering the HTML content, to change the node to an HTML template node type, we can utilize the drop event. Before that, define the template you need to render and bind the template to the nodeTemplate property of the diagram. Now, in the drop event, we can change the element content to empty and call the diagram.dataBind method.
Refer to the code below to learn how to change the HTML content node to a template:
<ng-template #nodeTemplate let-data>
<ng-container>
<input type="button" id="button" value="node" />
</ng-container>
</ng-template>
public drop(args: IDropEventArgs): void {
if ((args.element as any).id.includes('node')) {
(args.element as any).shape.content = '';
this.diagram.dataBind();
}
}
Refer to the working sample for additional details and implementation: Sample