How to remove connectors from diagram if it do not gets connected to any node in Angular?
This article explains how to remove connectors from a diagram if they do not get connected to any node in Angular. In the Angular Diagram, the connectors are used to create a link between two points, ports, or nodes to represent the relationship between them. To connect the connector between two nodes, the connector must have a sourceID and a targetID.
You can remove the connector from the diagram when the connector’s end is not connected to the node. The connectors’ sourceID and targetID properties are used to identify whether the connector is connected to a node or not.
The following code shows how to remove the connector when the connector is not connected to the node on each end:
// Remove the connector when it is not connected to the node
public remove() {
for (let i = 0; i < this.diagram.connectors.length; i++) {
let connector = this.diagram.connectors[i];
if (connector.sourceID === '' || connector.targetID === '') {
this.diagram.remove(connector);
--i;
}
}
};
<input type="button" value="Remove" (click)="remove()" />
//Initialize the diagram
<ejs-diagram #diagram id="diagram" width="100%" height="600" [nodes]="nodes" [connectors]="connectors"
[getConnectorDefaults]='getConnectorDefaults'
(created)='create($event)' [getNodeDefaults]='getNodeDefaults'>
</ejs-diagram>
In the above code sample, the Click event is used to remove the connectors, which are not connected to any nodes. The Click event will get triggered after the Remove button is clicked. In that event, all the connectors in the diagram are iterated to check whether the sourceID and targetID are present in the connector. If the connector is not connected to any node means, then the sourceID and targetID will set as “”. If the sourceID and tragetID is empty means, the remove() method will remove that connector.
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning about how to remove connectors from a diagram if they do not get connected to any node in Angular.
You can refer to our Angular Diagram feature tour page to learn about its other groundbreaking feature representations. You can explore our Angular Diagram documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular 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 Angular Diagram and other Angular components.
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!