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

PPTX
Angular 2.0
PDF
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
PPTX
Angular 4
PDF
AngularJS Basics
PDF
New in Spring Framework 5.0: Functional Web Framework
PDF
Angular Weekend
Angular 2.0
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Angular 4
AngularJS Basics
New in Spring Framework 5.0: Functional Web Framework
Angular Weekend

What's hot (20)

PPTX
Coordinating Micro-Services with Spring Cloud Contract
PPTX
What’s expected in Spring 5
PDF
CraftCamp for Students - Introduction to AngularJS
PPTX
Angularjs Basics
PDF
Dynamic input tables lwc vs aura vs. visualforce
PPTX
Single Page Applications with AngularJS 2.0
PDF
What angular 13 will bring to the table
PDF
Scala quick start
PPTX
MuleSoft Meetup Warsaw Group DataWeave 2.0
PPTX
ASP.Net 5 and C# 6
KEY
Everything you need to know about HTML5 in 15 min
PDF
Introduction to React, Flux, and Isomorphic Apps
PPTX
Angular
PPTX
Reactive Micro Services with Java seminar
PPTX
Effective .NET Core Unit Testing with SQLite and Dapper
PDF
Reactive Thinking in Java
PPTX
Step by step guide to create theme for liferay dxp 7
PDF
Understanding Facebook's React.js
ODP
Developing Microservices using Spring - Beginner's Guide
PPTX
Seif_mike_gsoc_2014_cloudstack
Coordinating Micro-Services with Spring Cloud Contract
What’s expected in Spring 5
CraftCamp for Students - Introduction to AngularJS
Angularjs Basics
Dynamic input tables lwc vs aura vs. visualforce
Single Page Applications with AngularJS 2.0
What angular 13 will bring to the table
Scala quick start
MuleSoft Meetup Warsaw Group DataWeave 2.0
ASP.Net 5 and C# 6
Everything you need to know about HTML5 in 15 min
Introduction to React, Flux, and Isomorphic Apps
Angular
Reactive Micro Services with Java seminar
Effective .NET Core Unit Testing with SQLite and Dapper
Reactive Thinking in Java
Step by step guide to create theme for liferay dxp 7
Understanding Facebook's React.js
Developing Microservices using Spring - Beginner's Guide
Seif_mike_gsoc_2014_cloudstack
Ad

Viewers also liked (20)

ODP
Embrace HTTP with ASP.NET Web API
PDF
Modern angular 04_component_router
PDF
Capitulo3
PPTX
Amit K Sawant C.V. - Presentation
PDF
Bm 300 manual
PPT
asp .net training | asp.net course | asp.net training online | learn asp.net
PDF
Recent UX Success
PDF
Building Native Experiences with Electron
PPTX
Ievadprezentacija, Latvijas vecāku forums 2016
PPTX
Building HTTP APIs with ASP.NET Core
ODP
Unit207 slideshare cheryl_cripps_18.03.16
PDF
Cross-Platform Desktop Apps with Electron
PDF
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
PPTX
Biografy designer grafis
PPSX
Electron - Build cross platform desktop apps
PPTX
Asp.net orientation
PPTX
work and energy
PPTX
Ova001 Mixología Básica
PDF
CoffeeScript com Visual Studio e ASP.NET MVC
PPTX
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Embrace HTTP with ASP.NET Web API
Modern angular 04_component_router
Capitulo3
Amit K Sawant C.V. - Presentation
Bm 300 manual
asp .net training | asp.net course | asp.net training online | learn asp.net
Recent UX Success
Building Native Experiences with Electron
Ievadprezentacija, Latvijas vecāku forums 2016
Building HTTP APIs with ASP.NET Core
Unit207 slideshare cheryl_cripps_18.03.16
Cross-Platform Desktop Apps with Electron
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Biografy designer grafis
Electron - Build cross platform desktop apps
Asp.net orientation
work and energy
Ova001 Mixología Básica
CoffeeScript com Visual Studio e ASP.NET MVC
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Ad

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

PPTX
Angular 9
PDF
Angular meetup 2 2019-08-29
PDF
better-apps-angular-2-day1.pdf and home
PPTX
Angular js 2
PDF
Meetup SkillValue - Angular 6 : Bien démarrer son application
PPTX
Introduction to angular | Concepts and Environment setup
PPTX
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
PDF
Angular - Chapter 3 - Components
PPTX
Introduction to angular with a simple but complete project
PPT
Angular js
PPTX
Angular4 kickstart
PPTX
Angular IO
PPTX
Building a website with angular 2
PPT
Angular.ppt
PPT
Angular js
PDF
Angular2 with TypeScript
PPTX
mean stack
PPTX
AngularJS
PPTX
Angular Course.pptx
PPTX
What's new in Angular 2?
Angular 9
Angular meetup 2 2019-08-29
better-apps-angular-2-day1.pdf and home
Angular js 2
Meetup SkillValue - Angular 6 : Bien démarrer son application
Introduction to angular | Concepts and Environment setup
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
Angular - Chapter 3 - Components
Introduction to angular with a simple but complete project
Angular js
Angular4 kickstart
Angular IO
Building a website with angular 2
Angular.ppt
Angular js
Angular2 with TypeScript
mean stack
AngularJS
Angular Course.pptx
What's new in Angular 2?

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
top salesforce developer skills in 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administraation Chapter 3
PPTX
Transform Your Business with a Software ERP System
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
AI in Product Development-omnex systems
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction Database Management System for Course Database
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Choose the Right IT Partner for Your Business in Malaysia
top salesforce developer skills in 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
CHAPTER 2 - PM Management and IT Context
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administraation Chapter 3
Transform Your Business with a Software ERP System
Design an Analysis of Algorithms II-SECS-1021-03
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
AI in Product Development-omnex systems
ManageIQ - Sprint 268 Review - Slide Deck
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

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