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 install
in 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 install
aspreinstall
script in thepackage.json
. -
Reference the packed library in the
package.json
of 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-component
to scaffold a new Angular component. -
Then add a container
div
in thegraph-component.component.html
that hosts the yFiles GraphComponent and specify a size ingraph-component.component.css
for it. -
In
graph-component.component.ts
, instantiate a new GraphComponent in the containerdiv
with editing capabilities and a basic sample graph. See the contents of/src/app/graph-component/graph-component.component.ts
in this repository for the full implementation.Also, make sure to configure your
license.json
for the library (seegraph-component.component.ts
). -
Add the new component to the
/src/app/app.component.html
that 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.