Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro-Apps and Angular Elements -- Talk from ng...

Manfred Steyer
September 04, 2018
270

Micro-Apps and Angular Elements -- Talk from ngGraz, Sep. 2018

Contents:
- Micro Apps
- Web Components/ Custom Elements
- Implementing Micro Apps with Angular Elements
- DEMO
- Recipes

# Samples
https://github.com/manfredsteyer/Angular_MicroApps_Different_Technologies

# More Information and Workshops:
https://www.softwarearchitekt.at

Manfred Steyer

September 04, 2018
Tweet

More Decks by Manfred Steyer

Transcript

  1. @ManfredSteyer About me… • Manfred Steyer • SOFTWAREarchitekt.at • Angular

    Trainings and Consultancy • Google Developer Expert (GDE) Page ▪ 2 Manfred Steyer Public: Vienna, München, Zürich In-House: everywhere http://www.softwarearchitekt.at
  2. @ManfredSteyer ✓ Commodore 64 ✓ 1982 ✓ ~ 1 MHz

    ✓ 64 KB RAM ✓ Disks with 170 KB
  3. @ManfredSteyer µService Providing a (SPA based) Shell µApp µApp µApp

    Shell ✓ iframes ✓ Bootstrapping several SPAs ✓ Web Components
  4. @ManfredSteyer Custom Elements Custom HTML-Element, e. g. <date-picker> Behaves like

    build-in ones Write once; consume with any framework Can be polyfilled for all current browser
  5. @ManfredSteyer Shadow DOM Isolate CSS Parent cannot influence Component's layout

    Component cannot influence Parent or Siblings Can be emulated for all current browsers (w/ limitations)
  6. @ManfredSteyer µService µApp3 µApp2 µApp1 Shell Web Components for Macro-Architecture

    Shared Widget Shared Widget Shared Widget Web Components for Micro-Architecture
  7. @ManfredSteyer Shadow DOM • Baked-in • Emulation • @Component({ encapsulation:

    ViewEncapsulation.Emulated }) • Default • Shadow DOM • @Component({ encapsulation: ViewEncapsulation.Native }) • Can be turned off: • @Component({ encapsulation: ViewEncapsulation.None })
  8. @ManfredSteyer MicroApp as Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { }
  9. @ManfredSteyer MicroApp as Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { }
  10. @ManfredSteyer MicroApp as Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { } }
  11. @ManfredSteyer MicroApp as Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { const MicroAppElement = createCustomElement( MicroAppComponent, { injector: this.injector }); customElements.define('micro-app', MicroAppElement); } }
  12. @ManfredSteyer Lazy Loading const content = document.getElementById('content'); // Add script-Tag

    const script = document.createElement('script'); script.src = [...]; content.appendChild(script);
  13. @ManfredSteyer Lazy Loading const content = document.getElementById('content'); // Add script-Tag

    const script = document.createElement('script'); script.src = [...]; content.appendChild(script); // Add Element const element: HTMLElement = document.createElement('client-a'); element.addEventListener('message', (event) => [...]); element.setAttribute('appState', [...]); content.appendChild(element);
  14. @ManfredSteyer Bundles Custom Element 1 Custom Element 2 Custom Element

    3 Libraries: Angular, Bootstrap, … Libraries: Angular, Bootstrap, …
  15. @ManfredSteyer Sharing Libs Custom Element 1 Custom Element 2 Custom

    Element 3 Libraries: Angular, Bootstrap, … UMD ngx-build-plus Drawbacks: Complexity, no isolation
  16. @ManfredSteyer Blog > SOFTWAREarchitekt.at • A Software Architect's Approach Towards

    Using Angular (And SPAs In General) For Microservices Aka Microfrontends • Micro Apps With Web Components Using Angular Elements • Angular Elements: A dynamic Dashboard … • Angular, React, Vue.Js And Co. Peacefully United Thanks To Micro Apps And Web Components