Last updated on January 9, 2021
In this week of building anything with JavaScript, I would like to write an experience of integrating web component within an angular app.
Introduction
To demonstrate this, I have developed a Toaster
web component which is built with Vanilla JavaScript.
Here I share what we will have to do when integrating Toaster
web component library with Angular application step by step.
Integrating Web Component within an Angular App
- Generate an angular app either
Webpack
orangular-cli
way
- Then the ultimate dependency we have here is to include
webcomponentsjs
npm package which can be done by following way
npm i @webcomponents/webcomponentsjs
- And also install the required
Toaster
web component package
npm i vj-toaster -S
- Include the webcomponents and vj-toaster library reference to the
angular.json
configuration file like below,
{
"assets": [
{
"glob": "**/*.js",
"input": "node_modules/@webcomponents/webcomponentsjs",
"output": "webcomponents/"
}
],
"scripts" : [
"node_modules/vj-toaster/dist/vj-toaster.js"
]
}
There you go!!