This is a step-by-step description of how to add a yFiles graph component to a basic Angular application.
TL;DR Add yFiles as a dependency in the package.json and start importing yFiles classes in your project.
Run the Vue-Cli with > ng new yfiles-angular-cli-integration and select following options:
? Would you like to add Angular routing?No? Which stylesheet format whould you like to use?CSS
This creates a basic Angular project.
Adding yFiles as a dependency is as easy as installing an external library from the npm registry:
-
Add yFiles for HTML as npm dependency to the created project:
-
If you have a fresh yFiles for HTML package, you need to prepare the library package first by running
npm installin the package folder. This creates the development library and a tarball that can be installed as npm dependency in other projects. See also Working with the yFiles npm Module.Note: This sample project runs
npm installaspreinstallscript in thepackage.json. -
Reference the packed library in the
package.jsonof the project:"dependencies": { ... "yfiles": "../yFiles-for-HTML-Complete-2.4.0.3-Evaluation/lib-dev/es-modules/yfiles-24.0.2-eval-dev.tgz" },
-
-
Now install the newly added dependency with
npm install.
After installing the dependency, you can import classes from yfiles in your project. Since yFiles is installed as proper npm dependency, IDEs provide full code-completion and automatic imports out of the box to easily work with the library.
With the yFiles dependency, you can easily create a new Angular component that contains a yFiles GraphComponent.
-
Run
ng generate component graph-componentto scaffold a new Angular component. -
Then add a container
divin thegraph-component.component.htmlthat hosts the yFiles GraphComponent and specify a size ingraph-component.component.cssfor it. -
In
graph-component.component.ts, instantiate a new GraphComponent in the containerdivwith editing capabilities and a basic sample graph. See the contents of/src/app/graph-component/graph-component.component.tsin this repository for the full implementation.Also, make sure to configure your
license.jsonfor the library (seegraph-component.component.ts). -
Add the new component to the
/src/app/app.component.htmlthat was created by the Angular CLI.
And that's it. Run npm run start to serve the application at http://localhost:4200/ with a basic yFiles component.