Install Angular components in Creatio using the Angular Elements functionality. Angular Elements is an npm package that enables packing Angular components to Custom Elements and defining new HTML elements with standard behavior. Custom Elements is a part of the Web-Components standard.
Create a custom Angular component
1. Set up the Angular CLI development environment
To do this, install:
- Node.js® and npm package manager.
- Angular CLI.
To install Angular CLI, run the following command at the command prompt:
2. Create an Angular application
Run the ng new command at the command prompt and specify the application name. For example, angular-element-test.
3. Install the Angular Elements package
Go to the Creatio directory added on the previous step and run the following command at the command prompt.
4. Create an Angular component
To create a component, run the following command at the command prompt.
5. Register the component as a Custom Element
To transform the component into a custom HTML element, modify the app.module.ts file:
- Add the import of the createCustomElement module.
- Specify the component name in the entryComponents section of the module.
- Register the component under the HTML tag in the ngDoBootstrap method.
6. Build the application
-
Several *.js files will be generated as part of the project build. We recommend deploying the generated files as a single file to streamline the use of the web component. To do this, create the build.js script in the root of Angular project.
build.js exampleIf the web component uses the lodash library, merge main.js (as well as styles.js, if necessary) with the script that resolves lodash conflicts to ensure the library's compatibility with Creatio. To do this, create the tools directory and the lodash-fix.js file in the Angular project root.
lodash-fix.jsTo execute the build.js script, install the concat and fs-extra packages in the project as dev-dependency. To do this, run the following commands at the command prompt:
Install additional packagesBy default, you can set the settings of the browserslist file in the new application. These settings create several builds for browsers that support ES2015 and those that require ES5. For this example, build an Angular element for modern browsers.
browserslist example -
Add the element building commands to package.json. After the commands are executed, the business logic will be placed in a single angular-element-component.js file. Use this file going forward.
package.json
Connect the Custom Element to Creatio
Install the angular-element-component.js file you built in a Creatio package as file content.
1. Place the file in the package static content
To do this, copy the file to the Custom package name\Files\src\js directory. For example, MyPackage\Files\src\js.
2. Install the build in Creatio
To do this, configure the build path in the bootstrap.js file of the package to which to upload the component.
To upload bootstrap, specify the path to this file. To do this, create descriptor.json in Custom package name\Files.
Upload the file from the file system and compile Creatio.
3. Load the component to the required schema/module
Create a schema or module in the package to which to load the custom element. Load the schema or module to the dependency load block of the module.
4. Create an HTML element and add it to DOM
Work with data
The Angular component receives data using the public properties/fields marked with the @Input decorator.
Data retrieval is implemented via the event functionality. To do this, mark the public field of the EventEmiter<T> type with the @Output decorator. To initialize an event, call the emit(T) field method and pass the required data.
Add a button to angular-element.component.html.
Use Shadow DOM
Use Shadow DOM to block certain components created using Angular and installed in Creatio off the external environment.
The Shadow DOM mechanism encapsulates components within DOM. This mechanism adds a “shadow” DOM tree to the component, which cannot be addressed from the main document via the standard options. The tree may have isolated CSS rules, etc.
To toggle on Shadow DOM, add the encapsulation: ViewEncapsulation.ShadowDom property to the component decorator.
Create Acceptance Tests for Shadow DOM
Shadow DOM creates test problems for application components using cucumber acceptance tests. It is not possible to address the components within Shadow DOM from the root document via the standard selectors.
Instead, use shadow root as the root document and address the component elements through it.
Shadow root – the root component node within Shadow DOM.
Shadow host – the component node that contains Shadow DOM.
The BPMonline.BaseItem class implements the base Shadow DOM operation methods.
clickShadowItem() | Click an element within the Shadow DOM component. |
getShadowRootElement() | Returns the shadow root of the Angular component by the CSS selector. Use the shadow root to select other elements. |
getShadowWebElement() | Returns the instance of the element within Shadow DOM by the CSS selector. Use the waitForVisible parameter to specify whether to wait for the instance to become visible. |
getShadowWebElements() | Returns the instances of elements within Shadow DOM by the CSS selector. |
mouseOverShadowItem() | Hover over the element within Shadow DOM. |
waitForShadowItem() | Waits until the element within the Shadow DOM component becomes visible and returns its instance. |
waitForShadowItemExist() | Waits until the element within the Shadow DOM component becomes visible. |
waitForShadowItemHide() | Waits until the element within the Shadow DOM component becomes hidden. |