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

Advancing into new areas with Angular Elements and Ivy @BASTA 2019 in Mainz, Germany

Advancing into new areas with Angular Elements and Ivy @BASTA 2019 in Mainz, Germany

Manfred Steyer

September 25, 2019
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer Advancing into new areas with Angular Elements and Ivy

    Manfred Steyer SOFTWAREarchitekt.at ManfredSteyer
  2. @ManfredSteyer Contents 1) Basics 2) Lazy loading elements 3) External

    elements 4) Dealing with dependencies 5) Angular Ivy
  3. @ManfredSteyer About me … • Manfred Steyer SOFTWAREarchitekt.at • Angular

    Trainings and Consultancy • Google Developer Expert (GDE) • Angular Trusted Collaborator Page ▪ 10 Manfred Steyer Public: Frankfurt, Munich, Vienna In-House: Everywhere in Europe http://www.softwarearchitekt.at/workshops
  4. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], entryComponents: [DateComponent]

    }) export class AppModule { constructor(private injector: Injector) { const DateElement = createCustomElement( DateComponent, { injector: this.injector }); customElements.define('date-picker', DateElement); } }
  5. @ManfredSteyer Lazy Loading @Injectable({ providedIn: 'root' }) export class LazyDashboardTileService

    { constructor( private loader: NgModuleFactoryLoader, private injector: Injector ) {} }
  6. @ManfredSteyer Lazy Loading @Injectable({ providedIn: 'root' }) export class LazyDashboardTileService

    { constructor( private loader: NgModuleFactoryLoader, private injector: Injector ) {} load(): Promise<void> { const path = '[…]lazy-dashboard-tile.module#LazyDashboardTileModule'; } }
  7. @ManfredSteyer Lazy Loading @Injectable({ providedIn: 'root' }) export class LazyDashboardTileService

    { constructor( private loader: NgModuleFactoryLoader, private injector: Injector ) {} load(): Promise<void> { const path = '[…]lazy-dashboard-tile.module#LazyDashboardTileModule'; return this.loader.load(path).then(moduleFactory => { }); } }
  8. @ManfredSteyer Lazy Loading @Injectable({ providedIn: 'root' }) export class LazyDashboardTileService

    { constructor( private loader: NgModuleFactoryLoader, private injector: Injector ) {} load(): Promise<void> { const path = '[…]lazy-dashboard-tile.module#LazyDashboardTileModule'; return this.loader.load(path).then(moduleFactory => { moduleFactory.create(this.injector); […] }); } }
  9. @ManfredSteyer Load into consumer const script = document.createElement('script'); script.src =

    'assets/external-dashboard-tile.bundle.js'; document.body.appendChild(script);
  10. @ManfredSteyer Bundles Custom Element 1 Custom Element 2 Custom Element

    3 Libraries: Angular, RxJS, … Libraries: Angular, RxJS, …
  11. @ManfredSteyer Roadmap (details can change) • Ivy behind a flag

    Angular 8 (Spring 2019) • Ivy by default • No breaking changes Angular 9 (Fall 2019)
  12. @ManfredSteyer Where Ivy can help ✓ Widgets based on @angular/core,

    @angular/common  Libs like @angular/forms or @angular/router
  13. @ManfredSteyer Sharing Libs Custom Element 1 Custom Element 2 Custom

    Element 3 Libraries: Angular, RxJS, … UMD Drawbacks: Complexity, no isolation
  14. @ManfredSteyer More on SOFTWAREarchitekt.at • Angular Elements (5 Parts) •

    Web Components with Angular Ivy in 6 Steps • Architecture with Ivy (2 Parts so far) • A possible future without NgModules • Higher Order and Dynamic Components
  15. @ManfredSteyer Summary Dynamically Adding External Elements Enhancing Existing Apps (e.

    g. ASP.NET) Migration Path Ivy for UI-based Code ngx-build-plus: Sharing Dependencies