0.0.5 • Published 5 years ago
@xpr/embed v0.0.5
@xpr/embed - Angular Embed
An easy way to embed Angular application in another Angular application.
Install
npm install @xpr/embedEmbedded Application
Preparing embedded Angular app steps:
- Make sure your root components selector (usually
AppComponent) is notapp-root(to avoid collision with hosting app). - Add
@angular/elementsto your appng add @angular/elements - Add
ngx-build-plusbuilder and generate web-components polyfillsng add ngx-build-plus ng g ngx-build-plus:wc-polyfill Change your
AppModuleto define a custom element from your root componentimport {createCustomElement} from '@angular/elements'; ... export class AppModule implements DoBootstrap { constructor(private injector: Injector) { } ngDoBootstrap(appRef: ApplicationRef): void { const el = createCustomElement(AppComponent, {injector: this.injector}); customElements.define('my-app', el); } }Build yor app using
ng build --prod --output-hashing=none --single-bundle
Host Application
- Copy embedded generated files
main.js,polyfill-webcomp.jsandstyles.cssinto yoursrc/assetsdirectory of your host app. - Install
@xpr/embednpm i @xpr/embed - Import
XprEmbedmodule to yourAppModule - Add
xpr-embedtag to your template:<xpr-embed tag="my-app"></xpr-embed>