Quick Start
Get up and running with ngDiagram in minutes. This guide will help you create your first interactive diagram.
Installation
Section titled “Installation”npm install ng-diagram
Note: You can use yarn
or pnpm
too
Import Styles
Section titled “Import Styles”@import 'ng-diagram/styles.css';
Without these styles, the diagram components will not render properly.
Create Your First Diagram
Section titled “Create Your First Diagram”import { Component } from '@angular/core';import { NgDiagramComponent, initializeModel, provideNgDiagram } from 'ng-diagram';
@Component({ imports: [NgDiagramComponent], providers: [provideNgDiagram()], template: ` <ng-diagram [model]="model" /> `, styles: ` :host { display: flex; height: 300px; } `,})export class AppComponent { model = initializeModel({ nodes: [ { id: '1', position: { x: 100, y: 150 }, data: { label: 'Node 1' } }, { id: '2', position: { x: 400, y: 150 }, data: { label: 'Node 2' } }, ], edges: [ { id: '1', source: '1', sourcePort: 'port-right', targetPort: 'port-left', target: '2', data: {}, }, ], });}
That’s it! You now have a working diagram with default node and edge templates.
What’s Next?
Section titled “What’s Next?”Now that you have a basic diagram working, you can customize it to fit your specific needs. Here are the main areas you can explore:
Customize Your Nodes
Section titled “Customize Your Nodes”Create custom node templates with your own styling, content, and interactive elements:
Learn about Custom Nodes → | See Example →
Create Custom Edges
Section titled “Create Custom Edges”Design custom edge types with unique visual styles and routing:
Learn about Custom Edges → | See Example →
Add a Palette
Section titled “Add a Palette”Create a drag-and-drop interface for users to add nodes to your diagram:
Learn about Palette → | See Example →
Persistence & State Management
Section titled “Persistence & State Management”Save and restore your diagram state:
Learn about State Management → | See Example →
Ready to dive deeper? Start with Custom Nodes or explore our Examples to see ngDiagram in action!