SlideShare ist ein Scribd-Unternehmen logo
1 von 59
-Santosh Kumar Kar
What is AngularJS
• JavaScript MVC framework for the Web
• pure JavaScript and HTML
• Unit Testable
• For Web and Mobile
• Less code
• Can integrate 3rd party libraries such as jQueryUI/BootStrap
MVC
• The model is the driving force of the application. This is generally the
data behind the application, usually fetched from the server. Any UI
with data that the user sees is derived from the model, or a subset of
the model.
• The view is the UI that the user sees and interacts with. It is dynamic,
and generated based on the current model of the application
• The controller is the business logic and presentation layer, which
performs actions such as fetching data, and makes decisions such as
how to present the model, which parts of it to display, etc.
First Application ng-app
Task – 1
• Write a Angular Application which prints the value of below
expressions:
• 5 *5 + 2*2
• 10/5*2-100
AngularJS Directives
• Markers on DOM elements (such as elements, attributes, css, and
more).
• Used to create custom HTML tags that serve as new, custom widgets.
• AngularJS has built-in directives (ngBind, ngModel...)
directive
ng-app
• first and most important directive
• Tells the section of HTML that AngularJS controls
• Need to put in any tag, preferable at <html> or <body>
• Anything outside of the tag would not be processed
directive
ng-model, ng-bind
directive
ng-model
• used with input fields, user to enter any data and get access to the
value in JavaScript.
• In ng-model="n1", AngularJS stores the value that the user types into
in a variable called "n1"
directive
ng-bind
• Binds with the Angular JS variable
• ng-bind in <span>
<span ng-bind="n1"
is similar to
{{n1}}
Modules
• Modules in AngularJS are similar to packages in java
• Container for the different parts of your app – controllers, services,
filters, directives, etc.
• Can define its own controllers, services, factories, and directives
which are accessed throughout the module.
• Can depend on other modules as dependencies and made available to
all the code defined in this module.
• angular.module(‘myApp', []);
Creating a module with no dependencies
• angular.module(‘myApp', ['myapp.ui', 'yourapp.diagram']);
Creating a module with 2 other dependent modules
• angular.module(‘myApp');
• looks an existing module to make it available to use, add, or modify in the
current file.
Module name we
define
Array of dependent
modules
Modules
Controller
• Fetch data from the server for UI
• Are regular JavaScript Objects.
• ng-controller directive defines the application controller.
Parent module
Child modules
Defined 2 Controllers
Using parent module
only
Task – 2
• Write an Angular Application which prints current date and time on
the screen
controllerAs
• Can be used in AngularJS 1.2 and later
• Allows to define the variables on the controller instance using the this
keyword instead of $scope
• Directly can be referred through the controller from the HTML
controllerAs
$scope.name = 'some value'
changed to
this.name = 'some value';
ng-controller="EmpController"
changed to
ng-controller="EmpController as emp"
{{ name }}
changed to
{{ emp.name }}
directive
ng-repeat
• Similar to for each loop
• Allows to iterate over an array
• Allows to iterate over keys and values of an object
• Syntax: ng-repeat="eachVar in arrayVar"
Calculator
Task – 3
• Write an Angular Application as
• Create a list which stores value of 5 students (id, name, marks) in a school
• In HTML, print the name and marks of all the students.
Calculator
Calculator
Forms
• ng-submit
• ng-disabled = "myForm.$invalid"
• required
form
JS
Task – 4
• Write an Angular Application
• Add few controls with different validation
• Add a submit button in the form.
• Submit button should be enabled only when all the validations are passed.
Error Handling
• Form validation
• required
• ng-required
• ng-minlength
• ng-maxlength
• ng-pattern
• type="email"
• type="number"
• type="date"
• type="url"
Dependency
Injection
• Any service known to
AngularJS can be injected into
any other service, directive,
or controller by stating it as a
dependency.
• AngularJS will automatically
create the entire chain before
injecting.
Controller vs Services
Services
• Service that is a reusable API or substitutable objects, which can be
shared across our applications.
• A service in AngularJS can be implemented as a
• factory
• service
• provider
Service types
• Build-in
• Custom
Common built-In Services
• $window
• $log
• $http
• $location
• $timeout
• $interval
Points to remember:
• AngularJS prefixes all the services that are provided by the AngularJS library with the $ sign.
• when you create your own services, do not prefix them with a $ sign. It will just end up confusing
you and your team at some point in time
Injecting service
Order of Injection
Creating Our Own Service
Creating your own service
Data with $http
• Similar to request to the server from AJAX applications (using
XMLHttpRequests)
• Makes request
• reads response
• checks the error codes
• processes the server response
• Traditional
• var xmlhttp = new XMLHttpRequest();
• xmlhttp.open("GET", "http://myserver/api", true);
Few test cases:
Input: 1, output: 1
Input:10, output: A
Input:15, output: F
Task – 5
• Write a Angular Application
• Add a service, this will take a decimal number as input and print the
hexadecimal value of that number.
$http with REST APIs
• GET
• HEAD
• POST
• DELETE
• PUT
• JSONP
GET request
Task – 6
• Write a Angular Application
• Which consumes restful web-service with GET, POST, DELETE
(you can write a web-service or see some examples with node.js to create demo restful web-
service)
Unit Testing
Filters
• Process data and format values to present
• Applied on expressions in HTML
• Applied directly on data in our controllers and services
• Examples:
• Format timestamp to readable date string
• Add currency symbol on a number
Task – 7
• Write a Angular Application
• Use in-built filters and produce the below output
(you can write a web-service or see some examples with node.js to create demo restful web-
service)
Task – 8
• Write a Angular Application and use below built-in filters
• orderBy
• filter
• json
• limitTo
Custom Filters
Task – 8
• Write a custom filter which accepts a string value and prints every
alternate character in lower case preceding to a upper case character.
Test cases:
Input: AngularJS output:AnGuLaRjS
Filters in controllers
Routing with URL - myurl.html#/home
• You need Routing if
• we call hashbang URLs, not the standard URL
• You are developing a single page application
• You have multiple views for a single page (e.g. Home Page, About Us, Contact
Us etc.)
• For each request in a single page, you need to load one of the view as
presentation logic but you don’t want to refresh the page.
• You don’t need to load the whole page but only the contents of the view
• You need speed response by loading contents faster
Routing: how to code
• Import angular.js and angular-route.js
• Use dependancy model to ngRoute
var myvar = angular.module('org',['ngRoute']);
• Config the route provider
$routeProvider.when(url, {
template: string,
templateUrl: string,
controller: string, function or array,
controllerAs: string,
resolve: object<key, function>
});
Request in routing : ‘#’ factor
• Request in a common URLs:
# in URLs
Task – 9
Make 3 Angular applications (3 views)
• Home.html
• About.html
• Contact.html
In index.html, you need to define 3 links for home, about and contact.
On clicking the links it needs to route to respective views without
reloading the page.
(Note: You may need to deploy as an application in a server to make it work.)
Things to do:
• I didn’t cover the unit testing parts in AngularJS along with mocking
up in this presentation for each of the components. I request you to
go through the steps for unit testing in internet. If I get time I would
add unit testing in a separate presentation. Thank you.
Source Code at:
• https://github.com/santoshkar/Angular.git
Angular js for Beginnners

Weitere ähnliche Inhalte

Was ist angesagt?

ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina
 

Was ist angesagt? (20)

Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
MVC Training Part 1
MVC Training Part 1MVC Training Part 1
MVC Training Part 1
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Introduction to Knockout Js
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScript
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
jQuery
jQueryjQuery
jQuery
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Viper architecture
Viper architectureViper architecture
Viper architecture
 

Ähnlich wie Angular js for Beginnners

4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
Goutam Dey
 
AgularJS basics- angular directives and controllers
AgularJS basics- angular directives and controllersAgularJS basics- angular directives and controllers
AgularJS basics- angular directives and controllers
jobinThomas54
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 

Ähnlich wie Angular js for Beginnners (20)

4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angularjs
AngularjsAngularjs
Angularjs
 
Angularjs basic part01
Angularjs basic part01Angularjs basic part01
Angularjs basic part01
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Angular 4
Angular 4Angular 4
Angular 4
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju Pillai
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
AgularJS basics- angular directives and controllers
AgularJS basics- angular directives and controllersAgularJS basics- angular directives and controllers
AgularJS basics- angular directives and controllers
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMS
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 

Mehr von Santosh Kumar Kar

Mehr von Santosh Kumar Kar (11)

Smart home arduino
Smart home   arduinoSmart home   arduino
Smart home arduino
 
Operating electrical devices with PIR sensor. No coding, No controller
Operating electrical devices with PIR sensor. No coding, No controllerOperating electrical devices with PIR sensor. No coding, No controller
Operating electrical devices with PIR sensor. No coding, No controller
 
Temperature sensor with raspberry pi
Temperature sensor with raspberry piTemperature sensor with raspberry pi
Temperature sensor with raspberry pi
 
Pir motion sensor with raspberry pi
Pir motion sensor with raspberry piPir motion sensor with raspberry pi
Pir motion sensor with raspberry pi
 
Raspberry pi complete setup
Raspberry pi complete setupRaspberry pi complete setup
Raspberry pi complete setup
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Spring transaction part4
Spring transaction   part4Spring transaction   part4
Spring transaction part4
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
 
Springs
SpringsSprings
Springs
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Angular js for Beginnners

  • 2. What is AngularJS • JavaScript MVC framework for the Web • pure JavaScript and HTML • Unit Testable • For Web and Mobile • Less code • Can integrate 3rd party libraries such as jQueryUI/BootStrap
  • 3. MVC • The model is the driving force of the application. This is generally the data behind the application, usually fetched from the server. Any UI with data that the user sees is derived from the model, or a subset of the model. • The view is the UI that the user sees and interacts with. It is dynamic, and generated based on the current model of the application • The controller is the business logic and presentation layer, which performs actions such as fetching data, and makes decisions such as how to present the model, which parts of it to display, etc.
  • 5. Task – 1 • Write a Angular Application which prints the value of below expressions: • 5 *5 + 2*2 • 10/5*2-100
  • 6. AngularJS Directives • Markers on DOM elements (such as elements, attributes, css, and more). • Used to create custom HTML tags that serve as new, custom widgets. • AngularJS has built-in directives (ngBind, ngModel...)
  • 7. directive ng-app • first and most important directive • Tells the section of HTML that AngularJS controls • Need to put in any tag, preferable at <html> or <body> • Anything outside of the tag would not be processed
  • 9. directive ng-model • used with input fields, user to enter any data and get access to the value in JavaScript. • In ng-model="n1", AngularJS stores the value that the user types into in a variable called "n1"
  • 10. directive ng-bind • Binds with the Angular JS variable • ng-bind in <span> <span ng-bind="n1" is similar to {{n1}}
  • 11. Modules • Modules in AngularJS are similar to packages in java • Container for the different parts of your app – controllers, services, filters, directives, etc. • Can define its own controllers, services, factories, and directives which are accessed throughout the module. • Can depend on other modules as dependencies and made available to all the code defined in this module.
  • 12. • angular.module(‘myApp', []); Creating a module with no dependencies • angular.module(‘myApp', ['myapp.ui', 'yourapp.diagram']); Creating a module with 2 other dependent modules • angular.module(‘myApp'); • looks an existing module to make it available to use, add, or modify in the current file. Module name we define Array of dependent modules Modules
  • 13. Controller • Fetch data from the server for UI • Are regular JavaScript Objects. • ng-controller directive defines the application controller.
  • 14. Parent module Child modules Defined 2 Controllers Using parent module only
  • 15. Task – 2 • Write an Angular Application which prints current date and time on the screen
  • 16. controllerAs • Can be used in AngularJS 1.2 and later • Allows to define the variables on the controller instance using the this keyword instead of $scope • Directly can be referred through the controller from the HTML
  • 17. controllerAs $scope.name = 'some value' changed to this.name = 'some value'; ng-controller="EmpController" changed to ng-controller="EmpController as emp" {{ name }} changed to {{ emp.name }}
  • 18.
  • 19. directive ng-repeat • Similar to for each loop • Allows to iterate over an array • Allows to iterate over keys and values of an object • Syntax: ng-repeat="eachVar in arrayVar"
  • 20.
  • 22. Task – 3 • Write an Angular Application as • Create a list which stores value of 5 students (id, name, marks) in a school • In HTML, print the name and marks of all the students.
  • 25. Forms • ng-submit • ng-disabled = "myForm.$invalid" • required
  • 26. form
  • 27. JS
  • 28. Task – 4 • Write an Angular Application • Add few controls with different validation • Add a submit button in the form. • Submit button should be enabled only when all the validations are passed.
  • 29. Error Handling • Form validation • required • ng-required • ng-minlength • ng-maxlength • ng-pattern • type="email" • type="number" • type="date" • type="url"
  • 30. Dependency Injection • Any service known to AngularJS can be injected into any other service, directive, or controller by stating it as a dependency. • AngularJS will automatically create the entire chain before injecting.
  • 32. Services • Service that is a reusable API or substitutable objects, which can be shared across our applications. • A service in AngularJS can be implemented as a • factory • service • provider
  • 34. Common built-In Services • $window • $log • $http • $location • $timeout • $interval Points to remember: • AngularJS prefixes all the services that are provided by the AngularJS library with the $ sign. • when you create your own services, do not prefix them with a $ sign. It will just end up confusing you and your team at some point in time
  • 36. Creating Our Own Service
  • 37. Creating your own service
  • 38. Data with $http • Similar to request to the server from AJAX applications (using XMLHttpRequests) • Makes request • reads response • checks the error codes • processes the server response • Traditional • var xmlhttp = new XMLHttpRequest(); • xmlhttp.open("GET", "http://myserver/api", true);
  • 39. Few test cases: Input: 1, output: 1 Input:10, output: A Input:15, output: F Task – 5 • Write a Angular Application • Add a service, this will take a decimal number as input and print the hexadecimal value of that number.
  • 40. $http with REST APIs • GET • HEAD • POST • DELETE • PUT • JSONP
  • 42. Task – 6 • Write a Angular Application • Which consumes restful web-service with GET, POST, DELETE (you can write a web-service or see some examples with node.js to create demo restful web- service)
  • 44. Filters • Process data and format values to present • Applied on expressions in HTML • Applied directly on data in our controllers and services • Examples: • Format timestamp to readable date string • Add currency symbol on a number
  • 45.
  • 46. Task – 7 • Write a Angular Application • Use in-built filters and produce the below output (you can write a web-service or see some examples with node.js to create demo restful web- service)
  • 47. Task – 8 • Write a Angular Application and use below built-in filters • orderBy • filter • json • limitTo
  • 49. Task – 8 • Write a custom filter which accepts a string value and prints every alternate character in lower case preceding to a upper case character. Test cases: Input: AngularJS output:AnGuLaRjS
  • 51. Routing with URL - myurl.html#/home • You need Routing if • we call hashbang URLs, not the standard URL • You are developing a single page application • You have multiple views for a single page (e.g. Home Page, About Us, Contact Us etc.) • For each request in a single page, you need to load one of the view as presentation logic but you don’t want to refresh the page. • You don’t need to load the whole page but only the contents of the view • You need speed response by loading contents faster
  • 52. Routing: how to code • Import angular.js and angular-route.js • Use dependancy model to ngRoute var myvar = angular.module('org',['ngRoute']); • Config the route provider $routeProvider.when(url, { template: string, templateUrl: string, controller: string, function or array, controllerAs: string, resolve: object<key, function> });
  • 53.
  • 54. Request in routing : ‘#’ factor • Request in a common URLs: # in URLs
  • 55. Task – 9 Make 3 Angular applications (3 views) • Home.html • About.html • Contact.html In index.html, you need to define 3 links for home, about and contact. On clicking the links it needs to route to respective views without reloading the page. (Note: You may need to deploy as an application in a server to make it work.)
  • 56. Things to do: • I didn’t cover the unit testing parts in AngularJS along with mocking up in this presentation for each of the components. I request you to go through the steps for unit testing in internet. If I get time I would add unit testing in a separate presentation. Thank you.
  • 57.
  • 58. Source Code at: • https://github.com/santoshkar/Angular.git