AG • Focus on – Mobile & web-based application architectures – Interoperability, cross-device – Pragmatic end-to-end solutions • Microsoft MVP for ASP.NET (Architecture) ASP.NET Web API / vNext Advisory Board Member ASPInsider, AzureInsider • Google GDE for AngularJS • http://blogs.thinktecture.com/cweyer [email protected] @christianweyer 2
Cumbersome code • Lack of coding standards • Globals & CSS all over the place • No modularity, encapsulation (provided by the browsers) • No real application semantics 5
concept of components • We need a standardized set of APIs to build components – UI – “Face-less” • Declarative and imperative programming models to produce & consume components 7
an API • Create elements that extend from other elements • Logically bundle together custom functionality into a single tag • Extend API of existing DOM elements 16
not leak styling or scripts onto other parts • All markup and CSS are scoped to the host element – Styles defined inside shadow root won't affect parent document – Styles defined outside shadow root won't affect main page 17 Document Element (shadow host) Shadow root Contents
JavaScript – Compiles to ES5 or ES6 • Preferred approach by the Angular team • Is not needed to build applications with Angular 2 • Types are optional – Pick and choose wisely 25
to use features from the future today – E.g. Traceur, Babel, tsc • Module loader – Load ES6 modules, AMD, CommonJS and global scripts in the browser (and NodeJS) – E.g. SystemJS 26
}) @View({ template: '<div>This app is called {{ title }}</div>' }) class AppComponent { this.title = 'My super app'; } import {bootstrap} from 'angular'; import {AppComponent} from 'app'; bootstrap(AppComponent); <html> <body> <my-app></my-app> </body>
to call $scope.$apply • Magic resides inside Angular 2 library named zone.js • Overrides all standard browser APIs that are considered asynchronous • Injects its own implementation & uses it to monitor start and completion of any asynchronous activity 37
a view • Directives add behavior to a DOM element – Component can consist of directives 42 @Directive({ selector: '[x-large]' }) export class XLarge { constructor(public el: ElementRef) { this.el.nativeElement.style.fontSize = 'x-large'; } } <span x-large>Extra Large Text</span>
service • Angular team plans to add sophisticated advanced features like – Caching – Offline – etc. • We can simply use any HTTP functionality – Like the Fetch feature in modern browsers 45
process • Tools like gulp makes life easier – Transpilation – Concatenation – Minification – Release folder – and so on… • Angular 2 is agnostic to actual underlying build process 46
JavaScript code?“ – Don‘t marry to frameworks • „What about my .NET code?“ – Don‘t marry to frameworks • Adopt frameworks by using their features, not tying into the framework 48
into services or directives • Wrap data logic and manipulation in services – Do not tie to Angular-isms • Encapsulate UI in directives – No ng-controller – Your path to components and Angular 2 • Consider using ES6 or TypeScript today – Traceur, Babel 49
& 2 • Team is working on ng-upgrade – Library that enables calling Angular 1 code from Angular 2 and vice versa • Using Component Router from Angular 1.5 can further easen the path 50
(still Alpha) • Web Components as a standard not yet fully adopted • Angular 2 build heavily on the idea of Components • Angular 1.x is well & alive – Large projects are being built with it • Apply proven Angular 1.x patterns to have a ‚good‘ codebase – In preparation for a possible migration • Let‘s (re-)consider Angular 2 beginning of 2016… – New projects should really not use Alpha software 51