Wednesday, December 5, 2018

What are Angular Elements

Angular Elements is an interesting new feature introduced in Angular 6. Angular Elements allows us to create Angular Components, package them and allows us to re-use the components in non-Angular environments like jQuery, HTML etc.

Angular Elements are angular components which are packaged into Custom Elements. Custom Elements allows us to create custom HTML tags which have their pre-defined functionality, these custom tags can be used in any HTML page. Custom Elements is a Web Component feature which helps us create custom elements and reuse them in HTML pages.

The @angular/elements package exports a createCustomElement() API which is used to expose the Angular component as a Custom Element. It bridges the Angular's component interface and change detection functionality to the built-in DOM API.

Transforming a component to a custom element makes all of the required Angular infrastructure available to the browser. Creating a custom element is simple and straightforward, and automatically connects your component-defined view with change detection and data binding, mapping Angular functionality to the corresponding native HTML equivalents.

The createCustomElement() function converts the component into a class that can be registered with the browser as a custom element. After you register your configured class with the browser's custom-element registry, you can use the new element just like a built-in HTML element in content that you add directly into the DOM.  When your custom element is placed on a page, the browser creates an instance of the registered class and adds it to the DOM. The content is provided by the component's template, which uses Angular template syntax, and is rendered using the component and DOM data. Input properties in the component correspond to input attributes for the element.

Search Flipkart Products:
Flipkart.com

No comments: