{"id":21090998,"url":"https://github.com/robertfoobar/ng4-wc-sample","last_synced_at":"2026-05-07T21:39:54.888Z","repository":{"id":95202721,"uuid":"137192684","full_name":"robertfoobar/ng4-wc-sample","owner":"robertfoobar","description":"Sample code on how to integrate a Polymer 3 web component (hosted as ES6 JS module) into an Angular 4+ app","archived":false,"fork":false,"pushed_at":"2018-06-13T14:56:46.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T06:22:42.862Z","etag":null,"topics":["angular","angular4","polyfills","polymer","polymer-3","webcomponents"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertfoobar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-13T09:21:21.000Z","updated_at":"2018-06-13T14:59:08.000Z","dependencies_parsed_at":"2023-05-17T16:15:49.284Z","dependency_job_id":null,"html_url":"https://github.com/robertfoobar/ng4-wc-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robertfoobar/ng4-wc-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertfoobar%2Fng4-wc-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertfoobar%2Fng4-wc-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertfoobar%2Fng4-wc-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertfoobar%2Fng4-wc-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertfoobar","download_url":"https://codeload.github.com/robertfoobar/ng4-wc-sample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertfoobar%2Fng4-wc-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32757641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular4","polyfills","polymer","polymer-3","webcomponents"],"created_at":"2024-11-19T21:42:33.535Z","updated_at":"2026-05-07T21:39:54.874Z","avatar_url":"https://github.com/robertfoobar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Angular 4 and Polymer 3 web component integration\nI haven't found a detailed explanation on how to integrate ES6 style web component modules (here based on Polymer 3) into an Angular 4+ app. So I document it here.\n\n## Integration scenario\nImagine different teams developing web components running their own release cycle. So... \n* you want to integrate a web component hosted by a third party at a given URL / at runtime. \n* you explicitly don't want to use self-hosted NPM packages (although you could given the solution provided here).\n\n## Polyfill the Angular App\nYou need to polyfill older browsers that are not (yet) web components compliant:\nThis is the steps which caused a lot of issues for me because I wanted to support IE11 along with ever-green browsers. Theoretically there are two strategies on how to polyfill:\n1. Polymer-driven polyfilling: outside the angular app in index.html. Bootstrap Angular app second.\n2. Angular-driven polyfilling: let Angular bootstrap first, i.e. let angular do the polyfilling: Bootstrap web components second.\n\nIt turns out that (2) is IMHO the better way to go. (1) failed because of current [issues](https://github.com/webcomponents/webcomponentsjs/issues/942) in webcomponentsjs.\n\nSo, in order to polyfill just follow these steps:  \n```\n npm i @webcomponents/webcomponentsjs --save\n```\nin polyfills.ts add the following line after the zone polyfill:\n```\nimport '@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js';\n```\n\n## ES6 module loader for older browsers\nSince older browsers do not understand the JS module syntax, you need to have an adapter that enables these browsers to load such modules. I use a code snippet from [polyserve](https://github.com/Polymer/polyserve) which you can find under src/assets/esm-amd-loader.min.js. You need to include it in your index.html\n```\n  \u003cscript id=\"esm-amd-loader\" src=\"assets/esm-amd-loader.min.js\"\u003e\u003c/script\u003e\n```\nNote: This script node has an id which will be relevant later in the process.\n\n## Module loader service\nYou can only load modules *after* the angular app bootstrapped completely. Since the JS module loading process depends on the platform, i.e. older browsers don't understand js modules, you unfortunately need a few lines of additional bootstrapping code.\nThe module-loader.service.ts will handle this loading process. It will add html script tags after the esm-amd-loader script into the HTML head. You need to call the module-loader service during initialization of your app.component.ts:\n\n```\nngOnInit(): void {\n    this.webComponentLoader.load('https://localhost:8000/custom-polymer-element.js');\n  }\n```\n\n## Starting the app\nFirst you need to host a custom element under https://localhost:8000/custom-polymer-element.js for this to work:\n```\n npm i -g polymer-cli@1.7.2\n mkdir custom-polymer-element \u0026\u0026 cd custom-polymer-element\n polymer init polymer-3-element\n polymer serve --protocol https/1.1\n```\n\nThen you can install and start the app\n\n```\n npm install\n npm start\n```\n\n# Resources\n* [Using Web Components with Angular](https://www.youtube.com/watch?v=Ucq9F-7Xp8I)\n* [Polyserve Project](https://github.com/Polymer/tools/tree/master/packages/polyserve)\n* [Webcomponentsjs Project](https://github.com/webcomponents/webcomponentsjs)\n* [How to host es6 custom module in static HTML](https://github.com/robertfoobar/es6-custom-element)\n\n# Known issues\n* Accept self-signed dev SSL certificates from the polymer dev server otherwise HTTP requests from your Angular app will be cancelled.\n* Chrome initially blocks requests from http://localhost:4200 (angular hosting) to https://localhost:8000 (polymer hosting). You can use a [Chrome CORS plugin](https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi) to work around that for demo purposes. IE doesn't care about CORS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertfoobar%2Fng4-wc-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertfoobar%2Fng4-wc-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertfoobar%2Fng4-wc-sample/lists"}