synergycodes/ng-diagram/ng-diagram-fundamentals
Claude Code and agent skill by synergycodes/ng-diagram
- community
Checking that the SKILL.md file is still in the repository.
Use when starting any ng-diagram task or unsure how the library works - data flow, golden rules, system-owned node/edge fields, where NgDiagram services can be injected, and which ng-diagram skill to load next.
Install
npx vskill@latest install synergycodes/ng-diagram/ng-diagram-fundamentalsSKILL.md
ng-diagram fundamentals
How ng-diagram works, the rules that prevent most bugs, and where to look next. The skill map at the end names the skill that owns each topic.
Rules
- Import the styles globally.
@import 'ng-diagram/styles.css';goes in the global stylesheet (src/styles.cssor.scss), never in a component'sstyles. The library is styled through CSS variables on:root, and component styles are scoped. Seeng-diagram-setup. - One `provideNgDiagram()` per diagram. Put it in
providersof the component that renders<ng-diagram>, or of an ancestor that also renders your toolbar or sidebar. Services resolve to the nearest registration, so two diagrams under one registration fight over one engine. - Change the model only through the services (
NgDiagramModelService,NgDiagramSelectionService,NgDiagramNodeService, ...). Do not mutate node or edge objects or write to the adapter fromgetModel(): only the services run middlewares, routing, z-index and events. - `await` when the next line depends on the change, otherwise
voidthe promise. Neverawaita service call inside a middleware: the update pipeline is not re-entrant and the await deadlocks (seeng-diagram-middleware). - Never write system-owned fields:
measuredPorts,measuredBounds,measuredLabels,computedZIndex,computedHidden,sourcePosition/targetPositionof connected edge ends,pointsof auto-routed edges,sizeof auto-sized nodes. The library recomputes them and your value is lost. Readreferences/model-reference.mdwhen you need to know who owns a property. - Wait for initialization before working with a new model: use
(diagramInit)orisInitialized(). Calls made right after you assign a new model still reach the old model and are lost. - Hide elements with the `hidden` flag (since 1.4.0), not CSS `display: none`. CSS-hidden elements cannot be measured, so loading waits for the measurement timeout and logs warnings. See
ng-diagram-visibility. - Create every model with `initializeModel()` (pass a custom adapter through
initializeModelAdapter()), and give each diagram instance its own model. The adapter is destroyed together with its diagram.
How it works
- Each
<ng-diagram>has one engine. It is created when<ng-diagram>first renders and created again when you bind a new model. Before that, service methods throw[ngDiagram] Library engine not initialized yet. - Initialization ends when all visible elements are measured. Then
(diagramInit)fires andNgDiagramService.isInitialized()becomestrue; the canvas stays invisible until then. Seeng-diagram-model-init. - Events fire after a change is committed to the model.
- Since 1.3.0 every mutating method of
NgDiagramModelService,NgDiagramNodeService,NgDiagramSelectionService,NgDiagramClipboardService,NgDiagramGroupsServiceandNgDiagramViewportServicereturns a promise that resolves when the change is in the model (attachEdgeresolves to aboolean).NgDiagramServicesetters such asupdateConfig()andregisterRouting()are synchronous. Afterawait, getters (getNodeById(),getModel().getNodes()) are fresh. Thenodes(),edges()andmetadata()signals update with change detection and can lag behind.
Check the installed version and verify APIs
ng-diagram.d.tsholds the whole public API in one file, with TSDoc and@sincetags.- Component selectors and input/output names are in the
ɵɵComponentDeclaration<...>andɵɵDirectiveDeclaration<...>lines. - Members tagged
@internalcan change without notice; build on@publicAPIs (https://www.ngdiagram.dev/docs/policies/api-stability/). - The docs MCP server answers from docs bundled in its own npm package, which can be newer than your installed version. Check
@sincebefore you use an API it suggests. - Examples in these skills assume Angular 19+, where components are standalone by default. On Angular 18 add
standalone: trueto every component and directive from these examples, including those withoutimports: Angular 18 does not make them standalone by default, soimportsreports'imports' is only valid on a component that is standalone.and a non-standalone component cannot be listed in another component'simports.
Coordinates
- Flow coordinates are what the model stores.
node.positionis the node's top-left corner; units are pixels at zoom 1. - Group children keep global flow coordinates. Moving a group moves its children, but a child's
positionis never relative to the group. - Port geometry is relative to its node:
measuredPorts[i].positionis measured from the node'sposition. - Client coordinates come from DOM events (
clientX,clientY). Convert them withNgDiagramViewportService.clientToFlowPosition()and back withflowToClientPosition(). With viewport{ x, y, scale }, a flow pointpis drawn atp * scale + (x, y)from the top-left corner of<ng-diagram>. - APIs that take a position for content (
addNodes,paste(position),startLinkingFromPosition) expect flow coordinates.
Viewport API details: ng-diagram-viewport.
Where services can be injected
All NgDiagram*Service classes come from provideNgDiagram(). You can inject them in:
- the component that lists
provideNgDiagram()inproviders(in its own class too), - every component and directive in its template: toolbars, sidebars, the minimap, palettes,
- your node and edge template components (they render inside
<ng-diagram>), - your own
@Injectable()services listed in the sameprovidersarray.
Code outside that tree (a providedIn: 'root' service, a component not rendered inside the host's template, an overlay created with a root injector) gets NullInjectorError: No provider for NgDiagram...Service!. For a dialog opened from inside the diagram (node editor, context menu), pass the caller's injector: Angular CDK and Material dialogs accept { injector: this.injector } or { viewContainerRef: this.viewContainerRef }. Otherwise move provideNgDiagram() up to a common ancestor, or make the service diagram-scoped:
Symptom → fix
| Symptom | Cause and fix | |
|---|---|---|
| Diagram blank, unstyled or zero-height | Styles or container size: see ng-diagram-setup. | |
`NgDiagram services are not available. Please register all required services using provideNgDiagram() ...` | No registration above <ng-diagram>: see ng-diagram-setup. | |
NullInjectorError: No provider for NgDiagramModelService! in a toolbar, sidebar or service | Code outside the provideNgDiagram() tree: move the provider up or use a diagram-scoped @Injectable() (above). | |
[ngDiagram] Library engine not initialized yet. | Service method called before <ng-diagram> created its engine: see ng-diagram-model-init. | |
Changes made right after initializeModel(...) disappear | They reached the old model: see ng-diagram-model-init. | |
A value you set (measuredPorts, computedZIndex, sourcePosition, auto points) is overwritten | System-owned field: see references/model-reference.md. | |
nodes() shows the old state right after await | Signals lag: read with getters, see ng-diagram-state-updates. | |
Changing the object bound to [config] does nothing | Config is read when the engine is created: see ng-diagram-config. | |
Loading takes 2 s or more and logs [InitUpdater] Measurement timeout reached | Unmeasurable elements: see ng-diagram-model-init and ng-diagram-visibility. |
Skill map
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ng-diagram-fundamentals/SKILL.md
Popularity
- Repository stars
- 583
- Repository forks
- 41
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/synergycodes/ng-diagram/ng-diagram-fundamentals)