Developing Angular Widgets
This section describes how you can use Angular framework to develop your widgets.
#
Creating the Project#
About this taskYou can create a Web Component widget using Angular framework. The following instruction provides an example of creating a demo-web-component widget.
#
Procedure- Install Angular CLI running the command in your terminal ⁄ console. This will install the latest version of Angular available:
- Create a new Angular web component project file (demo-web-component in this case). As of Angular 17 the default app creation will create itself in standalone mode. This will not make use of an app.module file, however we want to enforce that the app.module file is created, hence the no-standalone flag. Note if prompted for stylesheets, press Enter key to select default CSS option and then N key to choose not to enable server-side rendering for this example.
- Navigate to the project folder and run the following command:
- Create your Angular component:
- Open your component and update View Encapsulation:
- Navigate to /src/app directory and import the following elements into app.module.ts
Note Section 7 is only relevant if running Angular 14 or below, as defining entryComponents is no longer required in more recent Angular versions 7. Add an entryComponents array with your component inside:
Remove the bootstrap array from the ngModule in app.module.ts.
Transform the Angular component into a Web Component adding the following code to the AppModule class in app.module.ts:
After importing the relevant dependencies your app.module.ts file should look like this:
Please note that this code will register the custom element when an instance of the Angular component is created. If you want to register the custom element when the application starts, you should move the custom element registration code to the main.ts file or another appropriate place in your application.
- Include the contents of your widget. You can use HTML, CSS, and JavaScript files.
#
Next stepThe component is now set up as a Web Component. At this point, the component files only contain the default Angular <my-web-component works!> example code. You can continue on with development in the HTML, JavaScript and CSS files. When your project is ready as a Web Component, you must build it for later use.
#
Building the Project#
About this taskYou must build the project to use your widget in Avaya Workspaces.
#
Procedure- From the root project folder, run the following command in your terminal / console:
2a. If running Angular above version 14, then an alternate approach will be done, using a service called webpack
run
In the root project folder, create a webpack.config.js file with the following contents
Now update your package.json file with the following script and run npm run build:elements to build the project:
2b. If running Angular 14 or before, in the root project folder, create a concatenate.js file with the following contents if running Angular 14 or below:
3b. Run the following command to install the required dependencies:
4b. Add the following build script into the package.json file. Note: When ran, it generates the Angular build files and uses the concatenate script to bundle them into a single file.
- To build and bundle your project, create the elements folder running the following command:
#
Next stepWhen your project is bundled and built, continue configuring the widget JSON file that you can import in the Avaya Workspaces Widget Manager.