SlideShare a Scribd company logo
Introduction to
Angular 2
FE Guild #3
Dor Moshe
AngularJS history
• AngularJS was originally developed in 2009 by Misko Hevery and Adam Abrons at Brat Tech.
• Misko Hevery started to work for Google in 2009.
• First version of AngularJS: 1 developer, 3 weeks, 1000 lines.
• AngularJS version 1.0 was released in 2012 by Google.
• Angular version 2 was released in September 2016 after 2 years development.
FE Guild – Introduction to Angular 2
https://www.youtube.com/watch?v=aZm3OcApTN4
WELCOME TO THE FUTURE
FE Guild – Introduction to Angular 2
Angular 2
• Angular 2 is a framework for building client applications (SPA) in HTML and
either JavaScript or languages like TypeScript or Dart that compile to JavaScript.
• Angular 2 is not a version upgrade, but a complete rewrite.
• Angular 2 is written in TypeScript.
• Angular 1.X will not end life until the majority of traffic has moved to 2.0
• Current versions are 2.3.0 and 1.6.0
FE Guild – Introduction to Angular 2
Why Angular 2?
• Components & components interaction
• Modularity - much core functionality has moved to modules, producing a lighter, faster core.
• AOT compilation.
• Simple routing.
• Incredible performances.
FE Guild – Introduction to Angular 2
Mobile
Development
Typescript
Improved DI
HDI
Lazy Loading
Support
Modern
browsers only
RIP PartsDocumentation
Reactive
Programming
FE Guild – Introduction to Angular 2
Typescript
• Developed and maintained by Microsoft.
• Superset of JavaScript that compiles to clean JavaScript output.
• Adds optional types, classes, and modules to JavaScript.
• Compiles to readable, standards-based JavaScript.
FE Guild – Introduction to Angular 2
Why Typescript?
• Type safety.
• Compile time error check.
• Annotations offer a powerful and very expressive way to describe elements.
• Ease of refactoring.
• IntelliSense auto suggest in code editors.
• Easy to adopt for backend developers (like java & C#).
• Angular2 Dependency Injection system is based on type reflection.
FE Guild – Introduction to Angular 2
Example
JavascriptTypescript
FE Guild – Introduction to Angular 2
• Ng2 ships as a collection of JavaScript modules.
• Each ng2 library name begins with the @angular prefix.
• You install them with the node package manager and import parts of them with js import statements.
• The architecture diagram identifies the eight main building blocks of an ng2 application:
• Modules
• Components
• Templates
• Metadata
Architecture
FE Guild – Introduction to Angular 2
• Data binding
• Directives
• Services
• Dependency injection
Architecture - Flow
• Write Angular applications by composing HTML templates with Angularized markup.
• Write component classes to manage those templates.
• Adding application logic in services.
• Boxing components and services in modules.
• Launch the app by bootstrapping the root module.
• Angular takes over, presenting your application content in a browser.
• Angular responding to user interactions according to the instructions you've provided.
FE Guild – Introduction to Angular 2
THINKING COMPONENTS
FE Guild – Introduction to Angular 2
Modern web is all about components
• Thinking of components instead of views improves decoupling and separation of
concerns.
• Components are composable and highly reusable.
• Easier to test.
• UX and UI teams integrate better.
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
A component is
• Controls a patch of screen called a view.
• Exported as a custom HTML tag, e.g. <item></item>
• Defined by an HTML template.
• Enhanced using the @component decorator.
• Controlled using its inputs and outputs.
• Initialized by Angular Dependency Injection engine.
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
TEMPLATE syntax
• Template tags: {{ expression }}. Execute arbitrary
expressions like {{ x+1 }}.
• Property binding: [key]=‘value’. Used to pass data to a
component.
• Event binding: (event)=‘expression’. Expression executed
anytime the registered event fires.
• 2-way binding: <input [(ngModel)]=‘u.name’> Requires
to import ‘FormsModule’ to be used.
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
Data flows down,
into components
Events flows up,
out of components
Example
FE Guild – Introduction to Angular 2
Component style – View encapsulation
• Emulated (default) - Styles from main HTML propagate to the component. Styles
defined in this component's @Component decorator are scoped to this component
only.
• Native (shadow DOM) - Styles from main HTML do not propagate to the
component. Styles defined in this component's @Component decorator are
scoped to this component only.
• None - Styles from the component propagate back to the main HTML and
therefore are visible to all components on the page.
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
// CSS - output (inside <head>)
// HTML - output (inside <head>)// Typescript
Introduction to
Angular 2
FE Guild #4
Dor Moshe
Part 2
FE Guild – Introduction to Angular 2
Mobile
Development
Typescript
Improved DI
HDI
Lazy Loading
Support
Modern
browsers only
Documentation
Reactive
Programming
ModularityComponents AOT
Simple
Routing
Performance
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
Directive
• A directive is a class with a directive metadata.
• There are three kind of directives:
1. Component: A component is a directive-with-a-template. A @Component
decorator is actually a @Directive decorator extended with template-oriented
features.
2. Structural directive: Alter layout by adding, removing, and replacing elements
in DOM. E.g *ngIf, *ngFor, *ngSwitch.
3. Attribute directive: Alter the appearance or behavior of an existing element.
E.g *ngStyle, *ngClass.
FE Guild – Introduction to Angular 2
Lifecycle Hooks
FE Guild – Introduction to Angular 2
Components & Directives shared Lifecycle Hooks
ngOnChanges Input property value changes
ngOnInit Initialization step
ngDoCheck Every change detection cycle
ngOnDestroy Before destruction
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
Service
• A service is the mechanism used to share functionalities over components.
• A services are injected using Dependency Injection mechanism.
• For example:
• Logging service
• Data service
• Message bus
• Tax calculator
• Application configuration
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
Pipe
• Pipes transform displayed values within a template.
• The pipe operator passes the result of an expression on the left to a pipe
function on the right.
• Many of the pipes provided by ng2 will be familiar if you've worked with
filters in ng1.x.
• Built-in pipes: DatePipe, JsonPipe, UpperCasePipe, LowerCasePipe, DecimalPipe,
SlicePipe, CurrencyPipe, AsyncPipe, I18nPluralPipe, PercentPipe.
FE Guild – Introduction to Angular 2
Custom Pipe - Example
FE Guild – Introduction to Angular 2
Dependency Injection
• A way to supply a new instance of a class with the fully-formed dependencies it
requires.
• Most dependencies are services.
• Angular uses dependency injection to provide
new components with the services they need.
• There is actually a tree of injectors that parallel an application's component tree.
• Ng2 has a Hierarchical Dependency Injection system.
FE Guild – Introduction to Angular 2
Hierarchical DI - Example
FE Guild – Introduction to Angular 2
Angular Module
• Help organize an application into cohesive blocks of functionality
• Takes a metadata object that identifies the module's own components, directives
and pipes.
• Making some of them public so external components can use them.
• May add service providers to the application dependency injectors.
• Every Angular app has a root module.
• Many Angular libraries are module e.g. FormsModule, HttpModule, RouterModule
• Many third party libraries are available as Angular modules e.g. Angular Material 2,
Ionic, ng2-bootstrap.
FE Guild – Introduction to Angular 2
Angular Module
• An Angular module is a class decorated with @NgModule metadata.
• The metadata:
• Declare which components, directives and pipes belong to the module.
• Make some of those classes public so that other component templates can use
them.
• Import other modules with the components, directives and pipes needed by the
components in this module.
• Provide services at the application level that any application component can use.
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
Bootstrapping
• Bootstrapping is an essential process in Angular - it is
where the application is loaded when Angular comes to
life.
• Bootstrapping ng2 applications is technically
different from ng1.x, but is still a straightforward
procedure.
FE Guild – Introduction to Angular 2
Main.ts
app.modules.ts
Key People
FE Guild – Introduction to Angular 2
Todd MottoMinko Gechev John Papa Misko Hevery Pascal Precht
Shai ReznikNir Kaufman Shmuela Jacobs
Rendering Architecture
• Separation of application logic from the graphical aspects of the application.
• One key aspect of the ng2 design is that the elements of the application do not
directly depend or access the elements of the render code, and vice versa.
• They can only communicate via a renderer transport. This leads to the following
properties:
• Application and render code can be supplied via separate files (compilation units).
• Application code can run in a separate process from the process where the
renderer code runs (e.g. web worker, server).
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
NgUpgrade
• Ng2 comes with built-in tools for migrating ng1 projects over to the ng2 platform.
• You can do it incrementally, by running the two frameworks side by side in the same application,
and porting ng1 components (and services) to ng2 one by one.
• Both of these are the actual, fully featured versions of the frameworks.
• The UpgradeModule in ng2 has been designed to make incremental upgrading seamless.
• The UpgradeAdapter is a service that can bootstrap and manage hybrid applications that support
both ng2 and ng1 code.
FE Guild – Introduction to Angular 2
That’s what many dev do
FE Guild – Introduction to Angular 2
and it works
Observables (RxJs)
“Observables open up a continuous channel of
communication in which multiple values of data
can be emitted over time […] Angular 2 uses
observables extensively - you'll see them in the
HTTP service and the event system…“
FE Guild – Introduction to Angular 2
Example
FE Guild – Introduction to Angular 2
Semantic Versioning
• Ng2 has moved to time-based release cycles so that we can plan ahead.
• Ng2 have a deprecation policy so that you know how to get notified of API
changes ahead of time.
• SemVer means that the version numbers are meaningful
• x.x.y - Patch version - backwards-compatible bug fixes.
• x.y.x - Minor version - adding functionality in a backwards-compatible manner.
• y.x.x - Major version - incompatible API changes.
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
NG-BE
FE Guild – Introduction to Angular 2
09.12.16
Next version - Angular 4 - March 2017
FE Guild – Introduction to Angular 2
• Angular 3 will be skipped.
• No breaking changes for stable APIs.
• Typescript 2.1 (Breaking changes with Typescript 1.8).
• Better ng2 compiler errors.
• Faster.
• Smaller.
• @angular/router v4.0.0
Component Inheritance (2.3.0)
• Metadata (decorators): metadata (e.g. @Input, @Output) defined in a derived class will override any
previous metadata in the inheritance chain otherwise the base class metadata will be used.
• Constructor: base class constructor will be used if the derived class doesn’t have one.
• Lifecycle hooks: parent lifecycle hooks (e.g. ngOnInit, ngOnChanges) will be called even when are not
defined in the derived class.
• Component inheritance do not cover templates and styles. Any shared DOM or behaviors must be
handled separately.
FE Guild – Introduction to Angular 2
Example: Pagination
Plunker
FE Guild – Introduction to Angular 2
Language Service Module (2.4.0)
• Provide support for Angular templates.
• API that the IDE can call to ask “what smart thing can I suggest at this position in this file?”
• By using it, IDEs will be able to provide more detailed errors and type completion.
• There is already a VS Code plugin.
FE Guild – Introduction to Angular 2
Additional features
• Change Detection (Zone.js) - How Angular decides that a component property value has
changed, when to update the screen, and how it uses zones to intercept asynchronous
activity and run its change detection strategies.
• Animations - Animate component behavior without deep knowledge of animation
techniques or CSS with Angular's animation library.
• Testing - Ng2 was designed with testability in mind as its predecessor.
FE Guild – Introduction to Angular 2
Additional Tools
• Angular-cli - Command line interface to scaffold and build ng2 apps. Help us to
create apps, run builds, do E2E tests, run and deploy ng2 application.
• Angular-material 2, ng2-bootstrap - UI component library for ng2 developers. Helps
in constructing attractive, consistent, responsive and functional web pages and web apps.
• Augury - chrome developer tool for debugging and profiling ng2 apps.
FE Guild – Introduction to Angular 2
Angular Universal
• Server-side rendering of ng2 applications.
• Why?
• Better Performance.
• Optimized for Search Engines – SEO
• The search engine needs to "guess" when the page is complete.
• SPA deep links are hard to get indexed.
• Site preview.
FE Guild – Introduction to Angular 2
Angular Universal – The Web App Gap
FE Guild – Introduction to Angular 2
Angular Universal – The Web App Gap
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
References
• ng2-ninja
• Tour of Heroes
• API Reference & Cookbook
• Angular Formal Blog
• Thoughtram Blog
• Todd Motto Blog
• Cheat Sheet
• Changelog
• Milestones
• Weekly Meeting Notes
FE Guild – Introduction to Angular 2
Angular 2 in production
FE Guild – Introduction to Angular 2
FE Guild – Introduction to Angular 2
The JS Framework battle

More Related Content

PDF
Angular 2 - An Introduction
PDF
Introduction to Angular 2
PPTX
PPTX
Angular 2
PDF
Introduction to angular 2
PDF
Angular 2 Essential Training
PDF
What is Angular version 4?
PDF
Tech Webinar: Angular 2, Introduction to a new framework
Angular 2 - An Introduction
Introduction to Angular 2
Angular 2
Introduction to angular 2
Angular 2 Essential Training
What is Angular version 4?
Tech Webinar: Angular 2, Introduction to a new framework

What's hot (20)

ODP
Introduction to Angular 2
PDF
Quick introduction to Angular 4 for AngularJS 1.5 developers
PPTX
Angular 4 Introduction Tutorial
PDF
Angular2 with type script
PDF
Angular2 with TypeScript
PDF
The evolution of Angular 2 @ AngularJS Munich Meetup #5
PPTX
PDF
Angular 2 - Core Concepts
PDF
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
PDF
Developing a Demo Application with Angular 4 - J2I
PPTX
Talk for DevFest 2021 - GDG Bénin
PPTX
PDF
Angular 2 - The Next Framework
PPTX
AngularJS2 / TypeScript / CLI
PPTX
Angular1x and Angular 2 for Beginners
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
PDF
Building Universal Applications with Angular 2
PPTX
Angular 2 - Better or worse
PPSX
Angular 4 fronts
PDF
Angular2 intro
Introduction to Angular 2
Quick introduction to Angular 4 for AngularJS 1.5 developers
Angular 4 Introduction Tutorial
Angular2 with type script
Angular2 with TypeScript
The evolution of Angular 2 @ AngularJS Munich Meetup #5
Angular 2 - Core Concepts
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Developing a Demo Application with Angular 4 - J2I
Talk for DevFest 2021 - GDG Bénin
Angular 2 - The Next Framework
AngularJS2 / TypeScript / CLI
Angular1x and Angular 2 for Beginners
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Building Universal Applications with Angular 2
Angular 2 - Better or worse
Angular 4 fronts
Angular2 intro
Ad

Similar to Introduction to angular 2 (20)

PPT
Angular.ppt
PPTX
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
PDF
5 Key Benefits of Migration
PPTX
Angular Course.pptx
PDF
Angular meetup 2 2019-08-29
PPTX
Angular TS(typescript)
PPTX
Introduction to Angular2
PPTX
Angular 2.0
PPTX
Reason to choose Angular JS for your Web Application
PPTX
AngularConf2016 - A leap of faith !?
PPTX
PPT on Angular 2 Development Tutorial
PDF
Getting Started with the Angular 2 CLI
PPTX
Angular 9
PDF
Building blocks of Angular
PDF
Building Blocks of Angular 2 and ASP.NET Core
PDF
Evolution and History of Angular as Web Development Platform.pdf
PPTX
Angular Basics.pptx
PDF
Angular 4 Interview Questions PDF By ScholarHat
PDF
Angular 2 - How we got here?
PPTX
Angular IO
Angular.ppt
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
5 Key Benefits of Migration
Angular Course.pptx
Angular meetup 2 2019-08-29
Angular TS(typescript)
Introduction to Angular2
Angular 2.0
Reason to choose Angular JS for your Web Application
AngularConf2016 - A leap of faith !?
PPT on Angular 2 Development Tutorial
Getting Started with the Angular 2 CLI
Angular 9
Building blocks of Angular
Building Blocks of Angular 2 and ASP.NET Core
Evolution and History of Angular as Web Development Platform.pdf
Angular Basics.pptx
Angular 4 Interview Questions PDF By ScholarHat
Angular 2 - How we got here?
Angular IO
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks

Introduction to angular 2

  • 1. Introduction to Angular 2 FE Guild #3 Dor Moshe
  • 2. AngularJS history • AngularJS was originally developed in 2009 by Misko Hevery and Adam Abrons at Brat Tech. • Misko Hevery started to work for Google in 2009. • First version of AngularJS: 1 developer, 3 weeks, 1000 lines. • AngularJS version 1.0 was released in 2012 by Google. • Angular version 2 was released in September 2016 after 2 years development. FE Guild – Introduction to Angular 2
  • 4. WELCOME TO THE FUTURE FE Guild – Introduction to Angular 2
  • 5. Angular 2 • Angular 2 is a framework for building client applications (SPA) in HTML and either JavaScript or languages like TypeScript or Dart that compile to JavaScript. • Angular 2 is not a version upgrade, but a complete rewrite. • Angular 2 is written in TypeScript. • Angular 1.X will not end life until the majority of traffic has moved to 2.0 • Current versions are 2.3.0 and 1.6.0 FE Guild – Introduction to Angular 2
  • 6. Why Angular 2? • Components & components interaction • Modularity - much core functionality has moved to modules, producing a lighter, faster core. • AOT compilation. • Simple routing. • Incredible performances. FE Guild – Introduction to Angular 2 Mobile Development Typescript Improved DI HDI Lazy Loading Support Modern browsers only RIP PartsDocumentation Reactive Programming
  • 7. FE Guild – Introduction to Angular 2
  • 8. Typescript • Developed and maintained by Microsoft. • Superset of JavaScript that compiles to clean JavaScript output. • Adds optional types, classes, and modules to JavaScript. • Compiles to readable, standards-based JavaScript. FE Guild – Introduction to Angular 2
  • 9. Why Typescript? • Type safety. • Compile time error check. • Annotations offer a powerful and very expressive way to describe elements. • Ease of refactoring. • IntelliSense auto suggest in code editors. • Easy to adopt for backend developers (like java & C#). • Angular2 Dependency Injection system is based on type reflection. FE Guild – Introduction to Angular 2
  • 10. Example JavascriptTypescript FE Guild – Introduction to Angular 2
  • 11. • Ng2 ships as a collection of JavaScript modules. • Each ng2 library name begins with the @angular prefix. • You install them with the node package manager and import parts of them with js import statements. • The architecture diagram identifies the eight main building blocks of an ng2 application: • Modules • Components • Templates • Metadata Architecture FE Guild – Introduction to Angular 2 • Data binding • Directives • Services • Dependency injection
  • 12. Architecture - Flow • Write Angular applications by composing HTML templates with Angularized markup. • Write component classes to manage those templates. • Adding application logic in services. • Boxing components and services in modules. • Launch the app by bootstrapping the root module. • Angular takes over, presenting your application content in a browser. • Angular responding to user interactions according to the instructions you've provided. FE Guild – Introduction to Angular 2
  • 13. THINKING COMPONENTS FE Guild – Introduction to Angular 2
  • 14. Modern web is all about components • Thinking of components instead of views improves decoupling and separation of concerns. • Components are composable and highly reusable. • Easier to test. • UX and UI teams integrate better. FE Guild – Introduction to Angular 2
  • 15. FE Guild – Introduction to Angular 2
  • 16. FE Guild – Introduction to Angular 2
  • 17. A component is • Controls a patch of screen called a view. • Exported as a custom HTML tag, e.g. <item></item> • Defined by an HTML template. • Enhanced using the @component decorator. • Controlled using its inputs and outputs. • Initialized by Angular Dependency Injection engine. FE Guild – Introduction to Angular 2
  • 18. FE Guild – Introduction to Angular 2
  • 19. TEMPLATE syntax • Template tags: {{ expression }}. Execute arbitrary expressions like {{ x+1 }}. • Property binding: [key]=‘value’. Used to pass data to a component. • Event binding: (event)=‘expression’. Expression executed anytime the registered event fires. • 2-way binding: <input [(ngModel)]=‘u.name’> Requires to import ‘FormsModule’ to be used. FE Guild – Introduction to Angular 2
  • 20. FE Guild – Introduction to Angular 2 Data flows down, into components Events flows up, out of components
  • 21. Example FE Guild – Introduction to Angular 2
  • 22. Component style – View encapsulation • Emulated (default) - Styles from main HTML propagate to the component. Styles defined in this component's @Component decorator are scoped to this component only. • Native (shadow DOM) - Styles from main HTML do not propagate to the component. Styles defined in this component's @Component decorator are scoped to this component only. • None - Styles from the component propagate back to the main HTML and therefore are visible to all components on the page. FE Guild – Introduction to Angular 2
  • 23. Example FE Guild – Introduction to Angular 2 // CSS - output (inside <head>) // HTML - output (inside <head>)// Typescript
  • 24. Introduction to Angular 2 FE Guild #4 Dor Moshe Part 2
  • 25. FE Guild – Introduction to Angular 2 Mobile Development Typescript Improved DI HDI Lazy Loading Support Modern browsers only Documentation Reactive Programming ModularityComponents AOT Simple Routing Performance
  • 26. FE Guild – Introduction to Angular 2
  • 27. FE Guild – Introduction to Angular 2
  • 28. FE Guild – Introduction to Angular 2
  • 29. FE Guild – Introduction to Angular 2
  • 30. Example FE Guild – Introduction to Angular 2
  • 31. Directive • A directive is a class with a directive metadata. • There are three kind of directives: 1. Component: A component is a directive-with-a-template. A @Component decorator is actually a @Directive decorator extended with template-oriented features. 2. Structural directive: Alter layout by adding, removing, and replacing elements in DOM. E.g *ngIf, *ngFor, *ngSwitch. 3. Attribute directive: Alter the appearance or behavior of an existing element. E.g *ngStyle, *ngClass. FE Guild – Introduction to Angular 2
  • 32. Lifecycle Hooks FE Guild – Introduction to Angular 2
  • 33. Components & Directives shared Lifecycle Hooks ngOnChanges Input property value changes ngOnInit Initialization step ngDoCheck Every change detection cycle ngOnDestroy Before destruction FE Guild – Introduction to Angular 2
  • 34. Example FE Guild – Introduction to Angular 2
  • 35. Service • A service is the mechanism used to share functionalities over components. • A services are injected using Dependency Injection mechanism. • For example: • Logging service • Data service • Message bus • Tax calculator • Application configuration FE Guild – Introduction to Angular 2
  • 36. Example FE Guild – Introduction to Angular 2
  • 37. Pipe • Pipes transform displayed values within a template. • The pipe operator passes the result of an expression on the left to a pipe function on the right. • Many of the pipes provided by ng2 will be familiar if you've worked with filters in ng1.x. • Built-in pipes: DatePipe, JsonPipe, UpperCasePipe, LowerCasePipe, DecimalPipe, SlicePipe, CurrencyPipe, AsyncPipe, I18nPluralPipe, PercentPipe. FE Guild – Introduction to Angular 2
  • 38. Custom Pipe - Example FE Guild – Introduction to Angular 2
  • 39. Dependency Injection • A way to supply a new instance of a class with the fully-formed dependencies it requires. • Most dependencies are services. • Angular uses dependency injection to provide new components with the services they need. • There is actually a tree of injectors that parallel an application's component tree. • Ng2 has a Hierarchical Dependency Injection system. FE Guild – Introduction to Angular 2
  • 40. Hierarchical DI - Example FE Guild – Introduction to Angular 2
  • 41. Angular Module • Help organize an application into cohesive blocks of functionality • Takes a metadata object that identifies the module's own components, directives and pipes. • Making some of them public so external components can use them. • May add service providers to the application dependency injectors. • Every Angular app has a root module. • Many Angular libraries are module e.g. FormsModule, HttpModule, RouterModule • Many third party libraries are available as Angular modules e.g. Angular Material 2, Ionic, ng2-bootstrap. FE Guild – Introduction to Angular 2
  • 42. Angular Module • An Angular module is a class decorated with @NgModule metadata. • The metadata: • Declare which components, directives and pipes belong to the module. • Make some of those classes public so that other component templates can use them. • Import other modules with the components, directives and pipes needed by the components in this module. • Provide services at the application level that any application component can use. FE Guild – Introduction to Angular 2
  • 43. FE Guild – Introduction to Angular 2
  • 44. FE Guild – Introduction to Angular 2
  • 45. FE Guild – Introduction to Angular 2
  • 46. Example FE Guild – Introduction to Angular 2
  • 47. Bootstrapping • Bootstrapping is an essential process in Angular - it is where the application is loaded when Angular comes to life. • Bootstrapping ng2 applications is technically different from ng1.x, but is still a straightforward procedure. FE Guild – Introduction to Angular 2 Main.ts app.modules.ts
  • 48. Key People FE Guild – Introduction to Angular 2 Todd MottoMinko Gechev John Papa Misko Hevery Pascal Precht Shai ReznikNir Kaufman Shmuela Jacobs
  • 49. Rendering Architecture • Separation of application logic from the graphical aspects of the application. • One key aspect of the ng2 design is that the elements of the application do not directly depend or access the elements of the render code, and vice versa. • They can only communicate via a renderer transport. This leads to the following properties: • Application and render code can be supplied via separate files (compilation units). • Application code can run in a separate process from the process where the renderer code runs (e.g. web worker, server). FE Guild – Introduction to Angular 2
  • 50. FE Guild – Introduction to Angular 2
  • 51. NgUpgrade • Ng2 comes with built-in tools for migrating ng1 projects over to the ng2 platform. • You can do it incrementally, by running the two frameworks side by side in the same application, and porting ng1 components (and services) to ng2 one by one. • Both of these are the actual, fully featured versions of the frameworks. • The UpgradeModule in ng2 has been designed to make incremental upgrading seamless. • The UpgradeAdapter is a service that can bootstrap and manage hybrid applications that support both ng2 and ng1 code. FE Guild – Introduction to Angular 2
  • 52. That’s what many dev do FE Guild – Introduction to Angular 2 and it works
  • 53. Observables (RxJs) “Observables open up a continuous channel of communication in which multiple values of data can be emitted over time […] Angular 2 uses observables extensively - you'll see them in the HTTP service and the event system…“ FE Guild – Introduction to Angular 2
  • 54. Example FE Guild – Introduction to Angular 2
  • 55. Semantic Versioning • Ng2 has moved to time-based release cycles so that we can plan ahead. • Ng2 have a deprecation policy so that you know how to get notified of API changes ahead of time. • SemVer means that the version numbers are meaningful • x.x.y - Patch version - backwards-compatible bug fixes. • x.y.x - Minor version - adding functionality in a backwards-compatible manner. • y.x.x - Major version - incompatible API changes. FE Guild – Introduction to Angular 2
  • 56. FE Guild – Introduction to Angular 2
  • 57. FE Guild – Introduction to Angular 2
  • 58. NG-BE FE Guild – Introduction to Angular 2 09.12.16
  • 59. Next version - Angular 4 - March 2017 FE Guild – Introduction to Angular 2 • Angular 3 will be skipped. • No breaking changes for stable APIs. • Typescript 2.1 (Breaking changes with Typescript 1.8). • Better ng2 compiler errors. • Faster. • Smaller. • @angular/router v4.0.0
  • 60. Component Inheritance (2.3.0) • Metadata (decorators): metadata (e.g. @Input, @Output) defined in a derived class will override any previous metadata in the inheritance chain otherwise the base class metadata will be used. • Constructor: base class constructor will be used if the derived class doesn’t have one. • Lifecycle hooks: parent lifecycle hooks (e.g. ngOnInit, ngOnChanges) will be called even when are not defined in the derived class. • Component inheritance do not cover templates and styles. Any shared DOM or behaviors must be handled separately. FE Guild – Introduction to Angular 2
  • 61. Example: Pagination Plunker FE Guild – Introduction to Angular 2
  • 62. Language Service Module (2.4.0) • Provide support for Angular templates. • API that the IDE can call to ask “what smart thing can I suggest at this position in this file?” • By using it, IDEs will be able to provide more detailed errors and type completion. • There is already a VS Code plugin. FE Guild – Introduction to Angular 2
  • 63. Additional features • Change Detection (Zone.js) - How Angular decides that a component property value has changed, when to update the screen, and how it uses zones to intercept asynchronous activity and run its change detection strategies. • Animations - Animate component behavior without deep knowledge of animation techniques or CSS with Angular's animation library. • Testing - Ng2 was designed with testability in mind as its predecessor. FE Guild – Introduction to Angular 2
  • 64. Additional Tools • Angular-cli - Command line interface to scaffold and build ng2 apps. Help us to create apps, run builds, do E2E tests, run and deploy ng2 application. • Angular-material 2, ng2-bootstrap - UI component library for ng2 developers. Helps in constructing attractive, consistent, responsive and functional web pages and web apps. • Augury - chrome developer tool for debugging and profiling ng2 apps. FE Guild – Introduction to Angular 2
  • 65. Angular Universal • Server-side rendering of ng2 applications. • Why? • Better Performance. • Optimized for Search Engines – SEO • The search engine needs to "guess" when the page is complete. • SPA deep links are hard to get indexed. • Site preview. FE Guild – Introduction to Angular 2
  • 66. Angular Universal – The Web App Gap FE Guild – Introduction to Angular 2
  • 67. Angular Universal – The Web App Gap FE Guild – Introduction to Angular 2
  • 68. FE Guild – Introduction to Angular 2
  • 69. FE Guild – Introduction to Angular 2
  • 70. References • ng2-ninja • Tour of Heroes • API Reference & Cookbook • Angular Formal Blog • Thoughtram Blog • Todd Motto Blog • Cheat Sheet • Changelog • Milestones • Weekly Meeting Notes FE Guild – Introduction to Angular 2
  • 71. Angular 2 in production FE Guild – Introduction to Angular 2
  • 72. FE Guild – Introduction to Angular 2 The JS Framework battle

Editor's Notes

  • #58: React in 15.4.0
  • #62: https://scotch.io/tutorials/component-inheritance-in-angular-2 https://medium.com/@gerard.sans/angular-2-new-features-in-angular-2-3-f2e73f16a09e#.3dvzmuq4u