SlideShare a Scribd company logo
1 of 24
Copyright © 2014 by Software Craftsmanship Guild. 
All rights reserved. No part of these materials may be reproduced, 
distributed, or transmitted in any form or by any means, including 
photocopying, recording, or other electronic or mechanical methods, without 
the prior written permission of the Software Craftsmanship Guild. For 
permission requests, write to the Software Craftsmanship Guild, addressed 
“Attention: Permissions Coordinator,” at the address below. 
Software Craftsmanship Guild 
526 S. Main St, Suite 609 
Akron, OH 44311
AngularJS Fundamentals 
Software Craftsmanship Guild
Lesson Goals 
Learn about SPA (single page applications) and 
how Google’s AngularJS Framework can help 
with the complexity.
What is a SPA App? 
Single Page Applications are pages that contain 
multiple views that are shown and hidden 
dynamically based on events. 
SPAs do not do full postbacks to the server to fully 
reload pages. They request data via ajax in the 
background. 
Gmail is a good example of a complex SPA 
application.
SPA Challenges 
• DOM Manipulation 
• History 
• Module Loading 
• Routing 
• Caching 
• Object Modeling 
• Data Binding 
• Ajax/Promises 
• View Loading
AngularJS Features 
• Data Binding 
• MVC 
• Routing 
• Testing 
• View Models 
• Views 
• Controllers 
• jqLite 
• Templates 
• History 
• Factories 
• Directives 
• Services 
• Dependency Injection 
• Validation
Download AngularJS 
Go to angularjs.org and download the 
latest version. 
Place the file in the Scripts folder of an 
ASP.NET MVC web application. 
Don’t forget to right click -> properties, 
and unblock the file. 
You can also install it from nuget
Add angular to the layout 
Add angular to the bundleconfig.cs file 
and reference the bundle in the shared 
layout page.
Directives 
A directive is a way to wire up angular 
to html elements to extend their 
behavior. 
Angular directives by convention are 
named ng-* where * is the directive 
name. 
For a simple example, we’re going to 
add a ng-app directive to our row div 
and tag a text input with a ng-model 
directive called name. 
Then anywhere in our html we can use 
double braces {{ name }} to bind to the 
value of the textbox model. This is 
called a “data binding expression”
The ng-repeat Directive 
The ng-repeat directive instructs 
angular to repeat an html element for 
every item in a collection. 
Here we have initialized so data (ng-init 
creates default data on page load) 
and we want to loop through that 
array and create a list item for each 
element in the array. 
ng-repeat is very similar to a foreach 
loop. 
All directives are in the angularjs 
documentation: 
http://docs.angularjs.org/api/ng.direct 
ive:ngRepeat
Using Filters 
In a data binding expression, we can 
use the pipe character to use filters 
that are built into angularjs. 
Let’s say we have an array of friend 
objects. We can use filters to use the 
value of a text input to filter the list 
and perform other common tasks like 
ordering data. 
We can also put filters on data binding 
expressions. 
Try doing {{ friend.name | uppercase }} 
There is a list of filters in the 
documentation with examples.
Views, Controllers, and Scope 
So far we have been working only in views. Views 
contain all your formatting and data binding syntax. 
Controllers are intended to contain all your 
calculations and business logic. 
Scope, or $scope as angular calls it, is the transport 
object that shuttles information back and forth 
between the controller and view.
Creating a View and 
Controller 
In angular, a controller is just a 
function that takes a $scope as a 
parameter. 
AngularJS uses dependency injection 
to pass a scope in, which starts as 
empty and then we can add data to it. 
Notice the usage of the new ng-controller 
directive to bind the 
containing elements to fields on the 
SimpleController. 
We can have many controllers on a 
page and even chain controllers within 
elements, overwriting or inheriting 
fields. 
It is common to have different 
controllers for different parts of a view.
Modules and Routes 
Modules in AngularJS are responsible 
for configuring routes. 
Routes can register views and 
controllers for a given URL. 
Controllers often call out to factory or 
service classes to handle their CRUD 
operations. 
Modules contain all these things and 
are referenced by name in ng-app 
* Image from Dan Wahlin
Creating a Module 
The angular.module command creates 
a named module and allows for 
passing in an array of other modules if 
you want to build in complex 
dependencies. 
Now all we need to do is add the 
controller to the module and then 
reference demoApp as the ng-app. 
It’s typical to have many controllers in 
a module, particularly in a singe page 
application.
Handling Routes 
Routes allow our app to dynamically 
load different views into our page 
based on what the user does. 
In order to enable routing, we must 
download the angular-route.js files 
into our script folders (nuGet). 
We can then reference them in our 
bundle config below angularjs. 
Now when we declare our 
angular.module, we can pass in 
ngRoute as a dependency and 
configure the $routeProvider in the 
module .config method like so: 
Notice each route takes a controller 
and a templateUrl that points to an 
html file in our project.
Handling Routes – Adding 
Views Part 1 
Let’s make two views numbered 1 and 
2. (Terrible naming I know) 
View1 will be responsible for adding 
new players to our list, and View2 will 
just display players. 
Here is the code for view 1. Notice the 
link to View 2. We define route links in 
angular by starting them with a #. 
Also new is the ng-click directive 
where we have named a function 
called addPlayer() to be called when 
the button gets clicked. We should 
also add code to our controller to 
handle that.
Handling Routes – Adding Views Part 2 
The second view will be our standard filter text box with list of players.
Last Step 
Wherever in our page we decide to inject the views, we 
simply use the ng-view directive as a placeholder.
Re-use in Angular 
AngularJS can use Factories, Services, and 
Providers in order to share data between 
different controllers. 
There are minor differences between the three. 
We will look at Factories.
Setting up a Factory 
A factory can be added to a module 
using the .factory syntax. 
We simply give a name to our factory 
and then embed all of our data calls 
into it. 
Then any controller that is registered 
with our module can call any of the 
factory methods so long as the factory 
is injected into the controller function 
as a parameter. 
You can even inject factories into other 
factories!
Upgrading our Factory to 
use Ajax 
Angular has a built-in $http object that 
handles all of the http verbs. We are 
going to set up a WebAPI controller to 
return our player list as a JSON string 
to be parsed on the client. 
First, add an empty WebAPI controller. 
If we didn’t check the WebAPI box 
before, we’ll have to make a slight 
modification to our global.asax file. 
Add using Sytem.Web.Http; 
Above the 
RouteConfig.RegisterRoutes() method 
put the following method call: 
GlobalConfiguration.Configure(WebAp 
iConfig.Register);
Create the Ajax View 
We will now add a new controller 
action to our home controller called 
Ajax(). The code will be similar to our 
other pages- we will use a module and 
a factory. 
The difference is that we will make a 
call to $http.get to the Web API URL of 
the Player controller (/api/player/) 
$http.get returns data to the .success 
method if successful, and .error if not, 
otherwise the rest of our binding code 
remains the same.
Posting Data 
Posting data is very similar, and 
angular does most of the heavy lifting 
for converting your object to JSON 
format, which WebAPI handles out of 
the box. 
Simply: 
1. Add a post method to the WebAPI 
and the angular factory that takes 
a player object. 
2. Add a form with two fields and a 
button. 
3. Bind them to a newPlayer object 
in the scope. 
4. Create a function to do the post 
and bind it to the button click 
Happy binding!

More Related Content

What's hot

Angular 4 fronts
Angular 4 frontsAngular 4 fronts
Angular 4 frontsbadal dubla
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.jsDev_Events
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor Woiwode
 
Full Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemFull Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemDigamber Singh
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian MüllerSebastian Holstein
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionOleksii Prohonnyi
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...Katy Slemon
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Katy Slemon
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppKaty Slemon
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction TutorialScott Lee
 
Angular Best Practices - Perfomatix
Angular Best Practices - PerfomatixAngular Best Practices - Perfomatix
Angular Best Practices - PerfomatixPerfomatix Solutions
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)Abhishek Anand
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceOleksii Prohonnyi
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 

What's hot (20)

Angular 4 fronts
Angular 4 frontsAngular 4 fronts
Angular 4 fronts
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Full Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemFull Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication System
 
Angular 9 New features
Angular 9 New featuresAngular 9 New features
Angular 9 New features
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: Introduction
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...
 
Angular js
Angular jsAngular js
Angular js
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
 
Angular Best Practices - Perfomatix
Angular Best Practices - PerfomatixAngular Best Practices - Perfomatix
Angular Best Practices - Perfomatix
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
 
Lecture 32
Lecture 32Lecture 32
Lecture 32
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: Performance
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 

Viewers also liked

AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day WorkshopShyam Seshadri
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Question 4
Question 4Question 4
Question 4Shan3009
 
Code for Nara 紹介
Code for Nara 紹介Code for Nara 紹介
Code for Nara 紹介康司 石塚
 
Rupicon 2014 useful design patterns in rails
Rupicon 2014 useful design patterns in railsRupicon 2014 useful design patterns in rails
Rupicon 2014 useful design patterns in railsrupicon
 
Яндекс.Украина "Яндекс.Метрика"
Яндекс.Украина "Яндекс.Метрика"Яндекс.Украина "Яндекс.Метрика"
Яндекс.Украина "Яндекс.Метрика"awgua
 
Oración celebración domund 2016
Oración celebración domund 2016Oración celebración domund 2016
Oración celebración domund 2016ildefonso casas
 
Restaurant busser kpi
Restaurant busser kpiRestaurant busser kpi
Restaurant busser kpidiretjom
 
10 different vft ideas
10 different vft ideas10 different vft ideas
10 different vft ideasAngela Plut
 
Photography plan
Photography planPhotography plan
Photography planDarcyB16
 
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...Sightsavers
 
Мобильная коммерция: кому, когда и зачем
Мобильная коммерция: кому, когда и зачемМобильная коммерция: кому, когда и зачем
Мобильная коммерция: кому, когда и зачемawgua
 

Viewers also liked (14)

AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Question 4
Question 4Question 4
Question 4
 
Code for Nara 紹介
Code for Nara 紹介Code for Nara 紹介
Code for Nara 紹介
 
Rupicon 2014 useful design patterns in rails
Rupicon 2014 useful design patterns in railsRupicon 2014 useful design patterns in rails
Rupicon 2014 useful design patterns in rails
 
Яндекс.Украина "Яндекс.Метрика"
Яндекс.Украина "Яндекс.Метрика"Яндекс.Украина "Яндекс.Метрика"
Яндекс.Украина "Яндекс.Метрика"
 
Oración celebración domund 2016
Oración celebración domund 2016Oración celebración domund 2016
Oración celebración domund 2016
 
Restaurant busser kpi
Restaurant busser kpiRestaurant busser kpi
Restaurant busser kpi
 
10 different vft ideas
10 different vft ideas10 different vft ideas
10 different vft ideas
 
Photography plan
Photography planPhotography plan
Photography plan
 
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...
Everybody Counts: Learnings from data disaggregated by disabilities (DDD) pil...
 
Мобильная коммерция: кому, когда и зачем
Мобильная коммерция: кому, когда и зачемМобильная коммерция: кому, когда и зачем
Мобильная коммерция: кому, когда и зачем
 
Presentase PPKN
Presentase PPKNPresentase PPKN
Presentase PPKN
 

Similar to AngularJS Fundamentals + WebAPI

Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting startedHemant Mali
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfJohnLeo57
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresherRavi Bhadauria
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJSYashobanta Bai
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSShyjal Raazi
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day OneTroy Miles
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaphp2ranjan
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaBharat Makwana
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesMohamad Al Asmar
 

Similar to AngularJS Fundamentals + WebAPI (20)

Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting started
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresher
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular js
Angular jsAngular js
Angular js
 
Starting with angular js
Starting with angular js Starting with angular js
Starting with angular js
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat Makwana
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key Features
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

AngularJS Fundamentals + WebAPI

  • 1. Copyright © 2014 by Software Craftsmanship Guild. All rights reserved. No part of these materials may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the Software Craftsmanship Guild. For permission requests, write to the Software Craftsmanship Guild, addressed “Attention: Permissions Coordinator,” at the address below. Software Craftsmanship Guild 526 S. Main St, Suite 609 Akron, OH 44311
  • 2. AngularJS Fundamentals Software Craftsmanship Guild
  • 3. Lesson Goals Learn about SPA (single page applications) and how Google’s AngularJS Framework can help with the complexity.
  • 4. What is a SPA App? Single Page Applications are pages that contain multiple views that are shown and hidden dynamically based on events. SPAs do not do full postbacks to the server to fully reload pages. They request data via ajax in the background. Gmail is a good example of a complex SPA application.
  • 5. SPA Challenges • DOM Manipulation • History • Module Loading • Routing • Caching • Object Modeling • Data Binding • Ajax/Promises • View Loading
  • 6. AngularJS Features • Data Binding • MVC • Routing • Testing • View Models • Views • Controllers • jqLite • Templates • History • Factories • Directives • Services • Dependency Injection • Validation
  • 7. Download AngularJS Go to angularjs.org and download the latest version. Place the file in the Scripts folder of an ASP.NET MVC web application. Don’t forget to right click -> properties, and unblock the file. You can also install it from nuget
  • 8. Add angular to the layout Add angular to the bundleconfig.cs file and reference the bundle in the shared layout page.
  • 9. Directives A directive is a way to wire up angular to html elements to extend their behavior. Angular directives by convention are named ng-* where * is the directive name. For a simple example, we’re going to add a ng-app directive to our row div and tag a text input with a ng-model directive called name. Then anywhere in our html we can use double braces {{ name }} to bind to the value of the textbox model. This is called a “data binding expression”
  • 10. The ng-repeat Directive The ng-repeat directive instructs angular to repeat an html element for every item in a collection. Here we have initialized so data (ng-init creates default data on page load) and we want to loop through that array and create a list item for each element in the array. ng-repeat is very similar to a foreach loop. All directives are in the angularjs documentation: http://docs.angularjs.org/api/ng.direct ive:ngRepeat
  • 11. Using Filters In a data binding expression, we can use the pipe character to use filters that are built into angularjs. Let’s say we have an array of friend objects. We can use filters to use the value of a text input to filter the list and perform other common tasks like ordering data. We can also put filters on data binding expressions. Try doing {{ friend.name | uppercase }} There is a list of filters in the documentation with examples.
  • 12. Views, Controllers, and Scope So far we have been working only in views. Views contain all your formatting and data binding syntax. Controllers are intended to contain all your calculations and business logic. Scope, or $scope as angular calls it, is the transport object that shuttles information back and forth between the controller and view.
  • 13. Creating a View and Controller In angular, a controller is just a function that takes a $scope as a parameter. AngularJS uses dependency injection to pass a scope in, which starts as empty and then we can add data to it. Notice the usage of the new ng-controller directive to bind the containing elements to fields on the SimpleController. We can have many controllers on a page and even chain controllers within elements, overwriting or inheriting fields. It is common to have different controllers for different parts of a view.
  • 14. Modules and Routes Modules in AngularJS are responsible for configuring routes. Routes can register views and controllers for a given URL. Controllers often call out to factory or service classes to handle their CRUD operations. Modules contain all these things and are referenced by name in ng-app * Image from Dan Wahlin
  • 15. Creating a Module The angular.module command creates a named module and allows for passing in an array of other modules if you want to build in complex dependencies. Now all we need to do is add the controller to the module and then reference demoApp as the ng-app. It’s typical to have many controllers in a module, particularly in a singe page application.
  • 16. Handling Routes Routes allow our app to dynamically load different views into our page based on what the user does. In order to enable routing, we must download the angular-route.js files into our script folders (nuGet). We can then reference them in our bundle config below angularjs. Now when we declare our angular.module, we can pass in ngRoute as a dependency and configure the $routeProvider in the module .config method like so: Notice each route takes a controller and a templateUrl that points to an html file in our project.
  • 17. Handling Routes – Adding Views Part 1 Let’s make two views numbered 1 and 2. (Terrible naming I know) View1 will be responsible for adding new players to our list, and View2 will just display players. Here is the code for view 1. Notice the link to View 2. We define route links in angular by starting them with a #. Also new is the ng-click directive where we have named a function called addPlayer() to be called when the button gets clicked. We should also add code to our controller to handle that.
  • 18. Handling Routes – Adding Views Part 2 The second view will be our standard filter text box with list of players.
  • 19. Last Step Wherever in our page we decide to inject the views, we simply use the ng-view directive as a placeholder.
  • 20. Re-use in Angular AngularJS can use Factories, Services, and Providers in order to share data between different controllers. There are minor differences between the three. We will look at Factories.
  • 21. Setting up a Factory A factory can be added to a module using the .factory syntax. We simply give a name to our factory and then embed all of our data calls into it. Then any controller that is registered with our module can call any of the factory methods so long as the factory is injected into the controller function as a parameter. You can even inject factories into other factories!
  • 22. Upgrading our Factory to use Ajax Angular has a built-in $http object that handles all of the http verbs. We are going to set up a WebAPI controller to return our player list as a JSON string to be parsed on the client. First, add an empty WebAPI controller. If we didn’t check the WebAPI box before, we’ll have to make a slight modification to our global.asax file. Add using Sytem.Web.Http; Above the RouteConfig.RegisterRoutes() method put the following method call: GlobalConfiguration.Configure(WebAp iConfig.Register);
  • 23. Create the Ajax View We will now add a new controller action to our home controller called Ajax(). The code will be similar to our other pages- we will use a module and a factory. The difference is that we will make a call to $http.get to the Web API URL of the Player controller (/api/player/) $http.get returns data to the .success method if successful, and .error if not, otherwise the rest of our binding code remains the same.
  • 24. Posting Data Posting data is very similar, and angular does most of the heavy lifting for converting your object to JSON format, which WebAPI handles out of the box. Simply: 1. Add a post method to the WebAPI and the angular factory that takes a player object. 2. Add a form with two fields and a button. 3. Bind them to a newPlayer object in the scope. 4. Create a function to do the post and bind it to the button click Happy binding!