22.05.2019 .NET Day Bern - Angular Elements 5 «Angular is ideal for building complete applications, and our tooling, documentation and infrastructure are primarily aimed at this case.» Rob Wormald, Angular Team
Platform 22.05.2019 .NET Day Bern - Angular Elements 6 Dependency Injection Decorators Zones Compile Binding Render Material Mobile Universal CLI Language Service Augury ngUpdate Router Animation i18n
22.05.2019 .NET Day Bern - Angular Elements 7 «[…] but it’s quite challenging to use in scenarios that don’t fit that specific Singe Page Application model.» Rob Wormald, Angular Team
Use case 22.05.2019 .NET Day Bern - Angular Elements 8 ▪ Enhancing existing HTML Pages ▪ Content Management Systems integration ▪ Use components in other environments or frameworks ▪ Microfrontends ▪ Migrating Legacy Apps
Web Components 22.05.2019 .NET Day Bern - Angular Elements 11 Web Components are a set of features added by the W3C HTML Template Shadow DOM HTML Imports Custom Elements
Custom Elements 22.05.2019 .NET Day Bern - Angular Elements 13 Custom elements share the same API surface as native DOM objects: ▪ Attributes ▪ Properties ▪ Methods ▪ Events
Create and Define a Custom Element 22.05.2019 .NET Day Bern - Angular Elements 14 class myElement extends HTMLElement { … } customElements.define('my-element', myElement);
22.05.2019 .NET Day Bern - Angular Elements 21 let games = document.querySelector('world-cup-statistics'); games.addEventListener('country-change', event => { ... });
Enter Angular Elements 22.05.2019 .NET Day Bern - Angular Elements 24 Provides a bridge from angular concepts to web components. ▪ @HostBinding() => Attributes ▪ @Input() => Properties ▪ @Output() => CustomEvents ▪ Lifecycle Hooks => Reactions
Platform 22.05.2019 .NET Day Bern - Angular Elements 27 Dependency Injection Decorators Zones Compile Binding Render Material Mobile Universal CLI Language Service Augury ngUpdate Router Animation i18n
First Steps 22.05.2019 .NET Day Bern - Angular Elements 28 Update Angular CLI Update Angular CLI to > 6 ng new angularElements Create a new Angular CLI project ng add @angular/elements Add support for angular elements ng g c -v ShadowDom Generate new component
Angular Elements are the Host Element 22.05.2019 .NET Day Bern - Angular Elements 38 export class TestComponent implements OnInit { constructor(el: ElementRef) { el.nativeElement // <- Angular Element } @HostListener('click’) onHostClick($event) { ... } @HostBinding('attr.selected') isActive: boolean; }
Dependency Injection in Angular Elements 22.05.2019 .NET Day Bern - Angular Elements 40 Plattform Injector (Renderer) Module Injector (Services) Element Injector (ElementRef) Element Injector (ElementRef)
Angular Elements in V7 22.05.2019 .NET Day Bern - Angular Elements 46 ▪ It is just the beginning ▪ Size is too big for shipping in non Angular projects ▪ Will be much better with Ivy (V8) ▪ Will be much easier with V8+ ▪ Browser Support.
Optimize and combine bundle in a single file 22.05.2019 .NET Day Bern - Angular Elements 49 npm install ngx-build-plus Install package ngx-build-plus "build:element": "ng build --prod --output- hashing=none --single-bundle --keep-polyfills" Add script command npm run build:element Run Command ng add ngx-build-plus Install package ngx-build-plus