This is a working example of upgrading an AngularJS project using Angular Elements. I'm sure it will evolve over time, but for now, it features:
- ngx-build-plus for producing a single bundle
- Angular 8+
- Webpack 4+ for the AngularJS build
- AngularJS 1.7+ to include
ng-prop-*
andng-on-*
for working with Angular Elements
client-legacy
is the AngularJS project. It's a simple order system client.ordersystem-ce
is the Angular CLI project that includesngx-build-plus
and@angular/elements
.server
is a simple Express server that serves the data as well as the staticdist
folder inside ofclient-legacy
for a production build.
To create a new Angular Element:
- Create a new component (either with the CLI or manually).
- Add it to the
declarations
andentryComponents
array in the correct module (at the moment, justapp.module.ts
). - Create the custom element in the
ngDoBootstrap
function ofapp.module.ts
. This project iterates over an array of tuples to make creating multiple elements easier. You can just add a new tuple of the component and name to that array. - Run
npm run bundle:ce
to build the elements and move the files over to the AngularJS project. - Start the Express server (
npm start
in theserver
folder) and start the AngularJS Webpack server (npm run dev
in theclient-legacy
folder). - Navigate to
localhost:8080
to see your work in action.
To see the production build, run npm run build
in client-legacy
. With the Express server running, navigate to localhost:9001
.
I've incorporated the work of many people in my research on upgrading with Elements. Check out their projects:
- Elements series
- Upgrading with Web Components
- A Deep Look at Elements (ng-conf 2019)
- Beyond the Basics (ng-conf 2019)
- ngx-build-plus
ng-custom-element
(adds similar to functionality tong-prop-
andng-on-
to pre-AngularJS 1.7 projects)