Angular custom Element Customized Web Component

Source: Internet
Author: User
Tags export class

Angular Custom Web Components:

First, create a component named Mycustom.

Introduction of App.module:

... import {customcomponent} from './mycustom.component '; @NgModule ({  declarations:[appcomponent, Customcomponent],  entrycomponents:[customcomponent]    .....}) Export Class appmodule{}

  

Global registration:

App.component:

Import {Component,injector} from ' @angular/core '@angular/elements './mycustom.component '; Component ({}) Export class appcomponent{constructor (private injector:injector) {   const customelementref= createcustomelement (Createcustomelement,{injector});   Customelements.define (' my-test ', customelementref);}      }

Ok, this completes the ' my-test ' overall, and then it can be used as a Web component.

Go to our main HTML:

Index.html

Attention:

1. Put in front of the app-root, the effect is the same. There are no points in succession.

2. My-test's injection dependency, inherited from App.component. You can use it safely inside.

3. When you are a Web component, input cannot accept variables. Output does not take effect:

Ask:

Now that angular can register the global Web Component, can it be used in conjunction with react?

Of course, then the above:

Perfect operation.

 Angular component is registered as a Web Component technology. Let angular's agility soar instantly! But is it necessary to use it in conjunction with react?

Of course, it depends on your business requirements, such as your leader forcibly designated you to use react.

But when you face some complex components or page development, the relatively low efficiency of react, as well as large-scale repetitive computations, slow performance, can be very upsetting to you. At this point, perhaps you can consider using angular to quickly and easily provide a high-performance and stable component for your react project.

Add Ng6 once again lose weight, core library like jquery size, angular the future, a bright.

---

Before using the custom element:

To install the Webcomponents fill Library:

NPM install Webcomponents/webcomponentsjs--save;

Introduced in Polyfill.ts:

Import ' @webcomponents/webcomponentsjs/custom-elements-es5-adapter.js '

Angular custom Element Customized Web Component

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.