-
Notifications
You must be signed in to change notification settings - Fork 22
Web components
MSimonInria edited this page Jan 10, 2017
·
3 revisions
[From wikipedia]
Web Components are a set of features currently being added by the W3C to the HTML and DOM specifications that allow for the creation of reusable widgets or components in web documents and web applications. The intention behind them is to bring component-based software engineering to the World Wide Web. The components model allows for encapsulation and interoperability of individual HTML elements.
Web Components consist of 4 main features which can be used separately or all together:
- Custom Elements - APIs to define new HTML elements
- Shadow DOM - Encapsulated DOM and styling, with composition
- HTML Imports - Declarative methods of importing HTML documents into other documents
- HTML Templates - The
Integrate a web component in an Angular 2 application is very easy. It depends on web component type.
SystemJs is the most used module loader in many of the Angular 2 examples currently available.
- Configure systemjs.config.js
System.config({ map: { ..., 'angular2-library-example': 'node_modules/angular2-library-example', ... }, packages: { ..., 'angular2-library-example': { main: 'index' } } });
- Bootstrap the app (index.html)
System.import('build/App')
- Bootstrap the app (index.html)
`<script src="bundle.js"></script>`
- Bundle is created according to the following webpack configuration
module.exports = { entry: "./src/app.ts", output: { filename: "bundle.js" }, devtool: 'source-map', resolve: { extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'] }, module: { loaders: [ { test: /\.ts$/, loader: 'ts-loader' } ] } };
- Add the polymer webcomponent references in the index.html
`<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>`2. Enable shadowDOM (index.html)
`<script> window.Polymer = { dom: 'shadow' }; </script>`3. Import web component (index.html)
``