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

What's hot (20)

ODP
Introduction to Angular 2
Knoldus Inc.
 
PDF
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
PPTX
Angular 4 Introduction Tutorial
Scott Lee
 
PDF
Angular2 with type script
Ravi Mone
 
PDF
Angular2 with TypeScript
Rohit Bishnoi
 
PDF
The evolution of Angular 2 @ AngularJS Munich Meetup #5
Johannes Weber
 
PPTX
An Overview of Angular 4
Cynoteck Technology Solutions Private Limited
 
PDF
Angular 2 - Core Concepts
Fabio Biondi
 
PDF
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Edureka!
 
PDF
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
PPTX
Talk for DevFest 2021 - GDG Bénin
Ezéchiel Amen AGBLA
 
PPTX
Angular 5
Bartłomiej Narożnik
 
PDF
Angular 2 - The Next Framework
Commit University
 
PPTX
AngularJS2 / TypeScript / CLI
Domenico Rutigliano
 
PPTX
Angular1x and Angular 2 for Beginners
Oswald Campesato
 
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
PDF
Building Universal Applications with Angular 2
Minko Gechev
 
PPTX
Angular 2 - Better or worse
Vladimir Georgiev
 
PPSX
Angular 4 fronts
badal dubla
 
PDF
Angular2 intro
Shawn McKay
 
Introduction to Angular 2
Knoldus Inc.
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
Angular 4 Introduction Tutorial
Scott Lee
 
Angular2 with type script
Ravi Mone
 
Angular2 with TypeScript
Rohit Bishnoi
 
The evolution of Angular 2 @ AngularJS Munich Meetup #5
Johannes Weber
 
Angular 2 - Core Concepts
Fabio Biondi
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Edureka!
 
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
Talk for DevFest 2021 - GDG Bénin
Ezéchiel Amen AGBLA
 
Angular 2 - The Next Framework
Commit University
 
AngularJS2 / TypeScript / CLI
Domenico Rutigliano
 
Angular1x and Angular 2 for Beginners
Oswald Campesato
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
Building Universal Applications with Angular 2
Minko Gechev
 
Angular 2 - Better or worse
Vladimir Georgiev
 
Angular 4 fronts
badal dubla
 
Angular2 intro
Shawn McKay
 

Similar to Introduction to angular 2 (20)

PPT
Angular.ppt
Mytrux1
 
PPTX
Moving From AngularJS to Angular 2
Exilesoft
 
PPTX
What's new in Angular 2?
Alfred Jett Grandeza
 
PPTX
An evening with Angular 2
Mike Melusky
 
PPTX
An afternoon with angular 2
Mike Melusky
 
PDF
Angular2 tutorial
HarikaReddy115
 
PDF
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
PPTX
Angular Basics.pptx
AshokKumar616995
 
PPTX
Angular2 getting started by Stephen Lautier
Andrei Toma
 
PDF
Angular Notes.pdf
sagarpal60
 
ODP
Angular2
kunalkumar376
 
PPTX
Angularjs2 presentation
dharisk
 
PPTX
Angular 2 in-1
GlobalLogic Ukraine
 
PDF
Building Blocks of Angular 2 and ASP.NET Core
Levi Fuller
 
PPTX
Angular IO
Jennifer Estrada
 
PPTX
Angular2 and You
Joseph Jorden
 
PDF
Angular 2 overview
Jesse Warden
 
PDF
Angular2
SitaPrajapati
 
PPTX
Angular Course.pptx
Imdad Ullah
 
Angular.ppt
Mytrux1
 
Moving From AngularJS to Angular 2
Exilesoft
 
What's new in Angular 2?
Alfred Jett Grandeza
 
An evening with Angular 2
Mike Melusky
 
An afternoon with angular 2
Mike Melusky
 
Angular2 tutorial
HarikaReddy115
 
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
Angular Basics.pptx
AshokKumar616995
 
Angular2 getting started by Stephen Lautier
Andrei Toma
 
Angular Notes.pdf
sagarpal60
 
Angular2
kunalkumar376
 
Angularjs2 presentation
dharisk
 
Angular 2 in-1
GlobalLogic Ukraine
 
Building Blocks of Angular 2 and ASP.NET Core
Levi Fuller
 
Angular IO
Jennifer Estrada
 
Angular2 and You
Joseph Jorden
 
Angular 2 overview
Jesse Warden
 
Angular2
SitaPrajapati
 
Angular Course.pptx
Imdad Ullah
 
Ad

Recently uploaded (20)

PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Ad

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