Skip to content

bpmn-io/bpmn-js-example-angular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

107 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bpmn-js-example-angular

CI

An example how to integrate bpmn-js with an Angular application.

Integration Screenshot

Prerequisites

Assume you bootstrapped your application using the ng command:

ng new bpmn-js-app --defaults=true cd bpmn-js-app

Integrating bpmn-js

Include the style files for diagram-js and bpmn in your Angular.json file under projects > your project > architect > build > options > styles

"styles": [ "./node_modules/bpmn-js/dist/assets/diagram-js.css", "./node_modules/bpmn-js/dist/assets/bpmn-js.css", "./node_modules/bpmn-js/dist/assets/bpmn-font/css/bpmn.css", "src/styles.css" ],

Create a component similar to DiagramComponent:

import { AfterContentInit, Component, ElementRef, Input, OnChanges, OnDestroy, Output, ViewChild, SimpleChanges, EventEmitter } from '@angular/core'; import type Canvas from 'diagram-js/lib/core/Canvas'; import type { ImportDoneEvent } from 'bpmn-js/lib/BaseViewer'; /**  * You may include a different variant of BpmnJS:  *  * bpmn-viewer - displays BPMN diagrams without the ability  * to navigate them  * bpmn-modeler - bootstraps a full-fledged BPMN editor  */ import * as BpmnJS from 'bpmn-js/dist/bpmn-modeler.production.min.js'; @Component({ selector: 'app-diagram', template: `  <div #ref class="diagram-container"></div>  `, styles: [ `  .diagram-container {  height: 100%;  width: 100%;  }  ` ] }) export class DiagramComponent implements AfterContentInit, OnChanges, OnDestroy { // instantiate BpmnJS with component private bpmnJS: BpmnJS; // retrieve DOM element reference @ViewChild('ref', { static: true }) private el: ElementRef; @Input() private url: string; constructor() { this.bpmnJS = new BpmnJS(); this.bpmnJS.on<ImportDoneEvent>('import.done', ({ error }) => { if (!error) { this.bpmnJS.get<Canvas>('canvas').zoom('fit-viewport'); } }); } ngAfterContentInit(): void { // attach BpmnJS instance to DOM element this.bpmnJS.attachTo(this.el.nativeElement); } ngOnChanges(changes: SimpleChanges) { // re-import whenever the url changes if (changes.url) { this.loadUrl(changes.url.currentValue).then(xml => { return this.bpmnJS.importXML(xml); }); } } ngOnDestroy(): void { // destroy BpmnJS instance this.bpmnJS.destroy(); } private loadUrl(url: string) : Promise<string> { throw new Error('not implemented - return diagram XML from url'); } }

Test the Example

npm install npm run all

Additional Resources

License

MIT

About

An example how to integrate bpmn-js with an Angular application.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors