Skip to content

NgDiagramModelService

The NgDiagramModelService provides methods for accessing and manipulating the diagram’s model,

private modelService = inject(NgDiagramModelService);
// Add nodes
this.modelService.addNodes([node1, node2]);
  • NgDiagramBaseService
  • OnDestroy

readonly edges: Signal<Edge<object>[]>

Readonly signal of current edges in the diagram.


readonly metadata: Signal<Metadata<object>>

Readonly signal of current diagram metadata.


readonly nodes: Signal<Node[]>

Readonly signal of current nodes in the diagram.

addEdges(edges): void

Adds new edges to the diagram.

Edge<object>[]

Array of edges to add.

void


addNodes(nodes): void

Adds new nodes to the diagram.

Node[]

Array of nodes to add.

void


deleteEdges(ids): void

Deletes edges by their IDs.

string[]

Array of edge IDs to delete.

void


deleteNodes(ids): void

Deletes nodes by their IDs.

string[]

Array of node IDs to delete.

void


getEdgeById(edgeId): null | Edge<object>

Gets an edge by id.

string

Edge id.

null | Edge<object>

Edge or null if not found.


getModel(): ModelAdapter

Returns the current model that NgDiagram instance is using. Returns null if flowCore is not initialized.

ModelAdapter


getNearestNodeInRange(point, range): null | Node

Gets the nearest node in a range from a point.

Point

Point to check from.

number

Range to check in.

null | Node

Nearest node in range or null.


getNearestPortInRange(point, range): null | Port

Gets the nearest port in a range from a point.

Point

Point to check from.

number

Range to check in.

null | Port

Nearest port in range or null.


getNodeById(nodeId): null | Node

Gets a node by id.

string

Node id.

null | Node

Node or null if not found.


getNodesInRange(point, range): Node[]

Gets all nodes in a range from a point.

Point

Point to check from.

number

Range to check in.

Node[]

Array of nodes in range.


toJSON(): string

Serializes the current model to a JSON string.

string

The model as a JSON string.


updateEdge(edgeId, edge): void

Updates the properties of an edge.

string

Edge id.

Partial<Edge>

New edge properties.

void


updateEdgeData<T>(edgeId, data): void

Updates the data of an edge.

T extends undefined | Record<string, unknown>

string

Edge id.

T

New data to set for the edge (can be strongly typed).

void


updateEdges(edges): void

Updates multiple edges at once.

Pick<Edge<object>, "id"> & Partial<Edge<object>>[]

Array of edge updates (must include id and any properties to update).

void


updateNode(nodeId, node): void

Updates the properties of a node.

string

Node id.

Partial<Node>

New node properties.

void


updateNodeData<T>(nodeId, data): void

Updates the data of a node.

T extends undefined | Record<string, unknown>

string

Node id.

T

New data to set for the node (can be strongly typed).

void


updateNodes(nodes): void

Updates multiple nodes at once.

Pick<Node, "id"> & Partial<Node>[]

Array of node updates (must include id and any properties to update).

void