SlideShare a Scribd company logo
Building Blocks of
Angular 2 and ASP.NET Core
By Levi Fuller
Overview
• Angular CLI
• Overview & Commands
• Angular 2
• Overview
• Template Binding
• Decorators
• Lifecycle Hooks
• Directives
• Components
• Pipes
• Injectables (Services)
• Modules
• ASP.NET Core
• Overview
• Commands / Files
• Dependency Injection
• Controllers
• Pet Store Demo
Angular CLI
What is the Angular CLI?
Provides a set of commands which enable
you to:
• Scaffold a new app
• Scaffold the building blocks
• Run the application
• Build the application
• Deploy it
Scaffold Usage
Component ng g component my-new-component
Directive ng g directive my-new-directive
Pipe ng g pipe my-new-pipe
Service ng g service my-new-service
Class ng g class my-new-class
Interface ng g interface my-new-interface
Enum ng g enum my-new-enum
Module ng g module my-module
NG2 with the Angular CLI
• ng new <app-name>
• Creates new directory and creates the app
scaffolding inside the new directory
• ng serve
• Runs the application in memory via LiveReload server
• ng build
• Compiles the application and copies the output to
the `dist` directory
• ng github-pages:deploy
• Builds the app, setups a GitHub repo, publishes to
the GitHub page
Angular 2
Angular 2 Overview
Open source, front-end
framework for developing Single
Page Application (SPA’s)
• Supports TypeScript, Dart, or
JavaScript
• Component-based architecture
• Up to 5x faster than AngularJS
pet-
card.compo
nent
pet-
card.compo
nent
pet.options
app.component
Browse-pets.component
Data Binding
Data binding is the mechanism for coordinating what users see with the
component’s data values
<input type=“text” value=“Levi”>
{{person.name + ‘ is ’ + getAge(person.birthday)}}
<input [value]=“person.name”>
<input (input)=“name=$event.target.value”>
<input [(ngModel)]=“name”>
<input [ngModel]=“name” (ngModelChange)=“name=$event.target.value”>
<input [value]=“name” (input)=“name=$event.target.value”>
One-Time Initialization
This is not data binding
Event Binding
One-Way from view to
data source
Two-Way Binding
Property Binding +
Event Binding
Interpolation, Property,
Attribute, Class, and
Style Binding
Data source to view
One-WayTwo-Way
Template Binding Example
app.component
Decorators
• Decorators are functions that provide a declarative way to
add metadata to code
• Metadata tells Angular how to process a class
Lifecycle Hooks
• Implemented by components and directives
• Methods which are called when specific events
occur
• ngOnChanges() – called when data-bound input
properties are set/reset
• ngOnInit() – called shortly after the component is
created
• ngOnDestroy() – Called just before Angular destroys
the directive component
Lifecycle Hooks Example
app.componentlist.component
@Directive()
Directive is an attribute which can extend/modify the functionality of an element
• Target an element by its Selector – A CSS selector
• ‘[attributeToSelect]’
• ‘tag-to-select’
• ‘.class-to-select’
• Three Types
• Components - Directives with a template
• Structural Directives – Change the DOM layout by adding/removing DOM elements
• Attribute Directives – Change the appearance or behavior of an element
@Directive() Example
app.component hover-color.directive
@Component()
• A component is a directive with a template which contains logic for updating
or retrieving data to/from the view
@Component({
selector: ‘app-list’,
templateUrl: ‘./list.component.html’,
styleUrls: [‘./list.component.css’],
providers: [ListService]
})
export class ListComponent {}
Element to componentize
Path to View
Path to Styles
Component-
Scoped Services
@Component() Example
list.componentapp.component
@Pipe()
Pipes are used to transform data
• Two Types
• Pure – Only executed when a change is made to a primitive input value or a change
to an object reference
• Impure – Executed during every component change detection cycle
<p> {{ price | convertMoney : ’EUR’ : ’USD’ }} </p>
Object to
Transform
Pipe Name Argument 1 Argument 2
@Pipe() Example
app.component convert-money.pipe
@Injectable()
• Services are reusable classes which perform a specific task and are injected
using Angular 2’s hierarchical Dependency Injection system
• Constructor Injection
• Decorated with @Injectable() if any dependencies are required
• Singletons
• Domain scoped to Root Module or instance of Component
Root Module
Root DI Container
Component A
Instance Scoped DI Container
Component B
Instance Scoped DI Container
@Injectable() Example
app.component currency.service
@NgModule()
Helps organize application or library into cohesive blocks of functionality
• Declare what components, directives, and pipes (CDP’s) are used
• Provide services at the root module level
@NgModule({
imports: [FormsModule, CommonModule],
declarations: [ListComponent, HoverColorDirective],
exports: [ListComponent],
providers: [ListService]
})
export class CustomControlsModule {}
Modules used by any declared CDP’s, standalone
Declare any CDP’s used by this module
All modules which will exported and made available to the importing module
Any services used by the declared modules; Will be added to the root DI container
ASP.NET Core
ASP.NET Core Overview
• Built upon .NET Core, ASP.NET Core is a lean, cross-platform, open-source
framework for building web and cloud applications
• Supports C# and F#
• All Features/Libraries via NuGet packages (similar to NPM)
• Auto-Compiled Code
• Native Dependency Injection
• .NET Core and ASP.NET Core on Github
Dotnet Core Commands
• dotnet new
• creates a new project in the current directory
• dotnet restore
• installs the required NuGet packages
• dotnet run
• starts the application
• yo aspnet
• Options for scaffolding .NET Core apps
Components of ASP.NET Core
• Project.json
• Specify dependencies, configurations, frameworks
used and their versions
• Program.cs
• Application’s entry point
• Host is created and ran from here
• Startup.cs
• The configuration file for ASP.Net Core
• Inject services
• Configure services
Dependency Injection
Adds services to a container in order to achieve loose coupling between
objects and their dependencies
• Constructor Injection
• Service Types
• Transient
• Scoped
• Singleton
Public void ConfigureServices(IServiceCollection services) {
services.AddCors();
services.AddMvcCore().AddJsonFormatters();
services.AddScoped<PetService>();
services.AddSingleton<UtilityService>();
}
Public void Configure(IApplicationBuilder app, …) {
app.UseCors(cors => cors.WithOrigins(http://localhost:4200)
.AllowAnyHeader().AllowAnyMethod());
app.UseMvc();
}
Register Services
Use Services
Startup.cs
Controllers
Classes that handle browser requests and retrieves model data
[Route(“api/[controller]”)
public class PetsController : Controller {
private readonly PetService _petService;
public PetsController(PetService petService) {
_petService = petService;
}
[HttpGet(“{animalId}”)]
public List<Pet> Get(long animalId, bool isForSale = false) {
return _petService.GetPets(animalId: animalId, isForSale);
}
}
Route Template
http://myapp/api/pets
Constructor Injection
HTTP Verb
http://myapp/api/pets/4?isForSale=true
Inherit Controller base class
Query String Parameters

More Related Content

What's hot (20)

Coordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
What’s expected in Spring 5
What’s expected in Spring 5
Gal Marder
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Angularjs Basics
Angularjs Basics
Jayantha Sirisena
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforce
Mike Tetlow
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
What angular 13 will bring to the table
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
Scala quick start
Scala quick start
Sukjin Yun
 
MuleSoft Meetup Warsaw Group DataWeave 2.0
MuleSoft Meetup Warsaw Group DataWeave 2.0
Patryk Bandurski
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
Andy Butland
 
Everything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
Introduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
Angular
Angular
khoado2002
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
Gal Marder
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
Reactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
Understanding Facebook's React.js
Understanding Facebook's React.js
Federico Torre
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
Mohanraj Thirumoorthy
 
Seif_mike_gsoc_2014_cloudstack
Seif_mike_gsoc_2014_cloudstack
seif_100
 
Coordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
What’s expected in Spring 5
What’s expected in Spring 5
Gal Marder
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforce
Mike Tetlow
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Scala quick start
Scala quick start
Sukjin Yun
 
MuleSoft Meetup Warsaw Group DataWeave 2.0
MuleSoft Meetup Warsaw Group DataWeave 2.0
Patryk Bandurski
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
Andy Butland
 
Everything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
Introduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
Gal Marder
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
Reactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
Understanding Facebook's React.js
Understanding Facebook's React.js
Federico Torre
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
Mohanraj Thirumoorthy
 
Seif_mike_gsoc_2014_cloudstack
Seif_mike_gsoc_2014_cloudstack
seif_100
 

Viewers also liked (20)

Embrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web API
Filip W
 
Modern angular 04_component_router
Modern angular 04_component_router
Manfred Steyer
 
Capitulo3
Capitulo3
Jenifer Bautista
 
Amit K Sawant C.V. - Presentation
Amit K Sawant C.V. - Presentation
Amit Sawant - MRICS
 
Bm 300 manual
Bm 300 manual
leena leena
 
asp .net training | asp.net course | asp.net training online | learn asp.net
asp .net training | asp.net course | asp.net training online | learn asp.net
Nancy Thomas
 
Recent UX Success
Recent UX Success
Lou Susi
 
Building Native Experiences with Electron
Building Native Experiences with Electron
Ben Gotow
 
Ievadprezentacija, Latvijas vecāku forums 2016
Ievadprezentacija, Latvijas vecāku forums 2016
BJPLC
 
Building HTTP APIs with ASP.NET Core
Building HTTP APIs with ASP.NET Core
Filip W
 
Unit207 slideshare cheryl_cripps_18.03.16
Unit207 slideshare cheryl_cripps_18.03.16
Cheryl Cripps
 
Cross-Platform Desktop Apps with Electron
Cross-Platform Desktop Apps with Electron
David Neal
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
Biografy designer grafis
Biografy designer grafis
sigitartstudio
 
Electron - Build cross platform desktop apps
Electron - Build cross platform desktop apps
Priyaranjan Mohanty
 
Asp.net orientation
Asp.net orientation
Yogendra Tamang
 
work and energy
work and energy
Rks Ptl
 
Ova001 Mixología Básica
Ova001 Mixología Básica
Juanmendozaa
 
CoffeeScript com Visual Studio e ASP.NET MVC
CoffeeScript com Visual Studio e ASP.NET MVC
Giovanni Bassi
 
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Aaron Marisi
 
Embrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web API
Filip W
 
Modern angular 04_component_router
Modern angular 04_component_router
Manfred Steyer
 
Amit K Sawant C.V. - Presentation
Amit K Sawant C.V. - Presentation
Amit Sawant - MRICS
 
asp .net training | asp.net course | asp.net training online | learn asp.net
asp .net training | asp.net course | asp.net training online | learn asp.net
Nancy Thomas
 
Recent UX Success
Recent UX Success
Lou Susi
 
Building Native Experiences with Electron
Building Native Experiences with Electron
Ben Gotow
 
Ievadprezentacija, Latvijas vecāku forums 2016
Ievadprezentacija, Latvijas vecāku forums 2016
BJPLC
 
Building HTTP APIs with ASP.NET Core
Building HTTP APIs with ASP.NET Core
Filip W
 
Unit207 slideshare cheryl_cripps_18.03.16
Unit207 slideshare cheryl_cripps_18.03.16
Cheryl Cripps
 
Cross-Platform Desktop Apps with Electron
Cross-Platform Desktop Apps with Electron
David Neal
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
Biografy designer grafis
Biografy designer grafis
sigitartstudio
 
Electron - Build cross platform desktop apps
Electron - Build cross platform desktop apps
Priyaranjan Mohanty
 
work and energy
work and energy
Rks Ptl
 
Ova001 Mixología Básica
Ova001 Mixología Básica
Juanmendozaa
 
CoffeeScript com Visual Studio e ASP.NET MVC
CoffeeScript com Visual Studio e ASP.NET MVC
Giovanni Bassi
 
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Aaron Marisi
 
Ad

Similar to Building Blocks of Angular 2 and ASP.NET Core (20)

Angular 9
Angular 9
Raja Vishnu
 
Angular meetup 2 2019-08-29
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
better-apps-angular-2-day1.pdf and home
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
Angular js 2
Angular js 2
Ran Wahle
 
Meetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son application
Thibault Even
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
Ansley Rodrigues
 
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
CHETHANKUMAR274045
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular js
Angular js
yogi_solanki
 
Angular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Angular IO
Angular IO
Jennifer Estrada
 
Building a website with angular 2
Building a website with angular 2
Joseph Jorden
 
Angular.ppt
Angular.ppt
Mytrux1
 
Angular js
Angular js
Hritesh Saha
 
Angular2 with TypeScript
Angular2 with TypeScript
Rohit Bishnoi
 
mean stack
mean stack
michaelaaron25322
 
AngularJS
AngularJS
Yogesh L
 
Angular Course.pptx
Angular Course.pptx
Imdad Ullah
 
What's new in Angular 2?
What's new in Angular 2?
Alfred Jett Grandeza
 
Angular meetup 2 2019-08-29
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
better-apps-angular-2-day1.pdf and home
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
Angular js 2
Angular js 2
Ran Wahle
 
Meetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son application
Thibault Even
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
Ansley Rodrigues
 
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
CHETHANKUMAR274045
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Building a website with angular 2
Building a website with angular 2
Joseph Jorden
 
Angular.ppt
Angular.ppt
Mytrux1
 
Angular2 with TypeScript
Angular2 with TypeScript
Rohit Bishnoi
 
Angular Course.pptx
Angular Course.pptx
Imdad Ullah
 
Ad

Recently uploaded (20)

AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 

Building Blocks of Angular 2 and ASP.NET Core

  • 1. Building Blocks of Angular 2 and ASP.NET Core By Levi Fuller
  • 2. Overview • Angular CLI • Overview & Commands • Angular 2 • Overview • Template Binding • Decorators • Lifecycle Hooks • Directives • Components • Pipes • Injectables (Services) • Modules • ASP.NET Core • Overview • Commands / Files • Dependency Injection • Controllers • Pet Store Demo
  • 4. What is the Angular CLI? Provides a set of commands which enable you to: • Scaffold a new app • Scaffold the building blocks • Run the application • Build the application • Deploy it Scaffold Usage Component ng g component my-new-component Directive ng g directive my-new-directive Pipe ng g pipe my-new-pipe Service ng g service my-new-service Class ng g class my-new-class Interface ng g interface my-new-interface Enum ng g enum my-new-enum Module ng g module my-module
  • 5. NG2 with the Angular CLI • ng new <app-name> • Creates new directory and creates the app scaffolding inside the new directory • ng serve • Runs the application in memory via LiveReload server • ng build • Compiles the application and copies the output to the `dist` directory • ng github-pages:deploy • Builds the app, setups a GitHub repo, publishes to the GitHub page
  • 7. Angular 2 Overview Open source, front-end framework for developing Single Page Application (SPA’s) • Supports TypeScript, Dart, or JavaScript • Component-based architecture • Up to 5x faster than AngularJS pet- card.compo nent pet- card.compo nent pet.options app.component Browse-pets.component
  • 8. Data Binding Data binding is the mechanism for coordinating what users see with the component’s data values <input type=“text” value=“Levi”> {{person.name + ‘ is ’ + getAge(person.birthday)}} <input [value]=“person.name”> <input (input)=“name=$event.target.value”> <input [(ngModel)]=“name”> <input [ngModel]=“name” (ngModelChange)=“name=$event.target.value”> <input [value]=“name” (input)=“name=$event.target.value”> One-Time Initialization This is not data binding Event Binding One-Way from view to data source Two-Way Binding Property Binding + Event Binding Interpolation, Property, Attribute, Class, and Style Binding Data source to view One-WayTwo-Way
  • 10. Decorators • Decorators are functions that provide a declarative way to add metadata to code • Metadata tells Angular how to process a class
  • 11. Lifecycle Hooks • Implemented by components and directives • Methods which are called when specific events occur • ngOnChanges() – called when data-bound input properties are set/reset • ngOnInit() – called shortly after the component is created • ngOnDestroy() – Called just before Angular destroys the directive component
  • 13. @Directive() Directive is an attribute which can extend/modify the functionality of an element • Target an element by its Selector – A CSS selector • ‘[attributeToSelect]’ • ‘tag-to-select’ • ‘.class-to-select’ • Three Types • Components - Directives with a template • Structural Directives – Change the DOM layout by adding/removing DOM elements • Attribute Directives – Change the appearance or behavior of an element
  • 15. @Component() • A component is a directive with a template which contains logic for updating or retrieving data to/from the view @Component({ selector: ‘app-list’, templateUrl: ‘./list.component.html’, styleUrls: [‘./list.component.css’], providers: [ListService] }) export class ListComponent {} Element to componentize Path to View Path to Styles Component- Scoped Services
  • 17. @Pipe() Pipes are used to transform data • Two Types • Pure – Only executed when a change is made to a primitive input value or a change to an object reference • Impure – Executed during every component change detection cycle <p> {{ price | convertMoney : ’EUR’ : ’USD’ }} </p> Object to Transform Pipe Name Argument 1 Argument 2
  • 19. @Injectable() • Services are reusable classes which perform a specific task and are injected using Angular 2’s hierarchical Dependency Injection system • Constructor Injection • Decorated with @Injectable() if any dependencies are required • Singletons • Domain scoped to Root Module or instance of Component Root Module Root DI Container Component A Instance Scoped DI Container Component B Instance Scoped DI Container
  • 21. @NgModule() Helps organize application or library into cohesive blocks of functionality • Declare what components, directives, and pipes (CDP’s) are used • Provide services at the root module level @NgModule({ imports: [FormsModule, CommonModule], declarations: [ListComponent, HoverColorDirective], exports: [ListComponent], providers: [ListService] }) export class CustomControlsModule {} Modules used by any declared CDP’s, standalone Declare any CDP’s used by this module All modules which will exported and made available to the importing module Any services used by the declared modules; Will be added to the root DI container
  • 23. ASP.NET Core Overview • Built upon .NET Core, ASP.NET Core is a lean, cross-platform, open-source framework for building web and cloud applications • Supports C# and F# • All Features/Libraries via NuGet packages (similar to NPM) • Auto-Compiled Code • Native Dependency Injection • .NET Core and ASP.NET Core on Github
  • 24. Dotnet Core Commands • dotnet new • creates a new project in the current directory • dotnet restore • installs the required NuGet packages • dotnet run • starts the application • yo aspnet • Options for scaffolding .NET Core apps
  • 25. Components of ASP.NET Core • Project.json • Specify dependencies, configurations, frameworks used and their versions • Program.cs • Application’s entry point • Host is created and ran from here • Startup.cs • The configuration file for ASP.Net Core • Inject services • Configure services
  • 26. Dependency Injection Adds services to a container in order to achieve loose coupling between objects and their dependencies • Constructor Injection • Service Types • Transient • Scoped • Singleton Public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvcCore().AddJsonFormatters(); services.AddScoped<PetService>(); services.AddSingleton<UtilityService>(); } Public void Configure(IApplicationBuilder app, …) { app.UseCors(cors => cors.WithOrigins(http://localhost:4200) .AllowAnyHeader().AllowAnyMethod()); app.UseMvc(); } Register Services Use Services Startup.cs
  • 27. Controllers Classes that handle browser requests and retrieves model data [Route(“api/[controller]”) public class PetsController : Controller { private readonly PetService _petService; public PetsController(PetService petService) { _petService = petService; } [HttpGet(“{animalId}”)] public List<Pet> Get(long animalId, bool isForSale = false) { return _petService.GetPets(animalId: animalId, isForSale); } } Route Template http://myapp/api/pets Constructor Injection HTTP Verb http://myapp/api/pets/4?isForSale=true Inherit Controller base class Query String Parameters