initializeModel
since v0.8.0initializeModel(
model,injector?):ModelAdapter
Creates a model adapter with initial nodes, edges, and metadata.
This helper sets up a model instance ready for use in ng-diagram.
It must be run in an Angular injection context unless the injector option is provided manually.
⚠️ This is only for creating the initial model. Any changes to the model or access to current data should be done via NgDiagramModelService.
Parameters
Section titled “Parameters”Partial<Model> = {}
Initial model data (nodes, edges, metadata).
injector?
Section titled “injector?”Injector
Optional Angular Injector if not running inside an injection context.
Returns
Section titled “Returns”Example
Section titled “Example”// Create an empty modelmodel = initializeModel();
// Create a model with initial datamodel = initializeModel({ nodes: [{ id: '1', position: { x: 0, y: 0 }, data: { label: 'Node 1' } }], edges: [],});
// With an explicit injector (outside injection context)model = initializeModel({ nodes: [...], edges: [...] }, this.injector);