SlideShare ist ein Scribd-Unternehmen logo
1 von 40
An Introduction to a Powerful Framework

Santhosh Kumar
Github.com/santhotech
What is Angular JS
• A JavaScript framework (not for the faint hearted)
• Simple to develop complex applications

• Completely extensible
• Extremely flexible
• MVC Framework
How is it different
• Does not crave for control
• Perfectly happy to work within your boundaries

• Not greedy, can work with other libraries
• Do not force you to use it mandatorily for your complete app
• Lets you decide where its required and where its not
When Should you use it
• Scripts expanding at a rapid pace
• Too many UI Bindings

• Too many heavy lifting on the client side
• Completely restful web applications
• Single page web applications
A Little Comparison
JQuery
Mark up:
<input type=“text” id=“firstName” />
<div id=“firstNameBind”></div>
Script:
$(function(){
$("#firstName").keyup(function(){
$("#firstNameBind").html($("#firstName").val());
});
});
Lets do it the angular way
Angular
Mark up:
<input type=“text” ng-model=“rate.amount” />
<div>{{ rate.amount }}</div>
Script:
function OpController($scope) {
$scope.rate = { amount: 0 }
}
Things to Note
• Identifiers in the form of ID or Class or any other form is not required
in Angular
• Explicit bindings are not required
• $scope is directly used without the need to create it
• More natural syntax
• Data driven
Getting Started
• Download the full/minified version of Angular from Angularjs.org
<script src=“angular.js”></script>

• Using Google CDN
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.x.x/angular.min.js">
</script>
Specifying App Boundaries
<html ng-app>
<head>
<title>Shopping Cart</title>
<body >
<div ng-controller='CartController'>
<h1>Your Order</h1>
<div>Total: {{bill.totalCart | currency}}</div>
<div>Discount: {{bill.discount | currency}}</div>
<div>Subtotal: {{bill.subtotal | currency}}</div>
</div>
</body>
</html>
Everywhere ng-app touches…
• Ng-app specifies the overall boundary of the Application that
will be used by angular
• Ng-controller specifies the region that will be controlled by a
specific controller
$scope
• $scope is an object that can be injected anywhere
• Most data transitions happen through $scope
• It does not have to be created or instantiated
• It is available to be used directly through Angular dependency
injection
Dependency Injection
• Objects are injected when ever it is required only at the time it is required
• Lets you concentrate on important logic and not the dependencies that
affect the behaviour
• Angular is built completely on this principle
• Law of Demeter
• Principle of Least Knowledge
$scope is not the chosen one
• Many objects can be requested by adding it to the constructor
• $scope is not the only one
• $location, $route or even the directives we define can be
requested via dependency injection by specifying in the
constructor
Events the Angular Way
<form ng-submit="requestCash()" ngcontroller=“AccountController">
Amount: <input ng-change=“balanceCheckNeeded()" ngmodel=“currentDeposit">
Balance: {{availableBalance}}
<button>Withdraw!</button>
<button ng-click=”showLedger()">Ledger</button>
</form>
Hold your horses
• Don’t hate declarative events
• These are not the HTML events you are looking for
• These are Angular Directives

• No! We are not back to square one
They are still unobtrusive
• Cross Browser Compatibility
• All heavy lifting done by angular
• Events do not operate in global namespace

• They work within their own scope of the parents controller
Markup:

<div class=“sectionbar" ng-controller=“SectionController">
…
<li class="menu-item" ng-click="doSomeFunc()">Click Me</li>
…
</div>
<div class="mainArea" ng-controller="MainAreaController">
…
<div ng-click=" doSomeFunc()">...</div>
…
</div>
Script:
function SectionController($scope) {
$scope.doSomeFunc = doA;
}
function MainAreaController($scope) {
$scope.doSomeFunc = doB;
}
So that’s how it works
• Mapping the right functions for the right events is automatically
handled by Angular
• No explicit directive other than the controller references is required
• Declarative events reduce the hassle of fiddling with IDs and Classes
• Still it doesn’t violate any best practices
Modular Approach
• Angular is completely modular
• Namespaces allows perfect separation of application logic
• Avoids need for conflict resolution in terms of similar objects
<html ng-app='myApp'>
<head>
<title>Shopping Cart</title>
<body >
<div ng-controller=‘ShopController'>
<h1>Your Order</h1>
</div>
</body>
</html>
Script:
var myAppModule = angular.module('myApp',[]);
myAppModule.controller(‘ShopController',function($scope){
$scope.menuState = { show : false};
});
Useful Directives
Ng-Repeat
Mark up:
<div ng-repeat='item in items'>
<span>{{item.title}}</span>
<input ng-model='item.quantity'>
<span>{{item.price | currency}}</span>
<span>{{item.price * item.quantity | currency}}</span>
<button ng-click="remove($index)">Rfmove</button>
</div>
Script:
myAppModule.controller('CartController', function($scope) {
$scope.items = [
{title: 'Paint Pots1', quantity: 8, price: 3.95},
{title: 'Paint Pots2', quantity: 18, price: 12.95},
{title: 'Paint Pots3', quantity: 5, price: 6.95},
];
});
Event Directives
•
•
•
•
•
•
•

Ng-click
Ng-dblclick
Ng-submit
Ng-bind
Ng-show
Ng-hide
Ng-change
Double Curly Notation
• Angular way of defining expression
• May contain object references
{{ account.balance }}
• May point to variables which resolve to a value
{{ myAccountBalance }}
• May contain simple math expressions
{{ currentTotal – accountBalance }}
Note
•
•
•
•

The values within double curly are not evaluated using eval
They are evaluated by angular as special expression
They cannot contain loops, conditional constructs
They maintain state of the variable when there is a model
binding
Observer and Binding
• $scope object called $watch
• Once invoked keeps track of changes to an object

• Can invoke a method when a change has been detected
• Extremely useful to maintain object state when the object is modified
from several different locations
• Can watch an object, expression or a string that resolves to an object
How it works
myAppModule.controller(‘TaskController', function($scope) {
$scope.tasks = { pendingTask: 0};
taskCompleted = function() {
$scope.task.status = !$scope.task.isResolved;
};
$scope.$watch(‘task.pendingTask', taskCompleted);
});
• taskCompleted is invoked when ever there is a change in pendingTask
• Change can effect from any source, direct or binded
• Updates all binded dom elements automatically without explicit binding
Usage Warning
With great power comes great responsibility
-Spiderman’s Uncle
• While $watch seems like a powerful object (It really is) its usage
must be checked
• Watching wrong values may eat up the memory of the
application
• The expression provided must always be as less expensive as
possible
Communicating with the Server
• Provides $http which contains $get, $post that can be used to
communicate with web services
• Both the underlying methods as well as the wrappers can be
used
• Transformations are provided for both request and response
• Transformation can be intercepted
• Provides interface to handle the XHR requests efficiently
XHR has never been so easy
$http.get('api/user', {params: {id: '5'}
}).success(function(data, status, headers, config) {
// Do something successful.
}).error(function(data, status, headers, config) {
// Handle the error
});
Methods available for
• GET
• HEAD
• POST
• DELETE
• PUT
• JSONP
Method Chaining with then
var currentProfile =
fetchServerConfig().then(function(serverConfig) {
return fetchUserProfiles(serverConfig.USER_PROFILES, username);
}).then(function(profiles) {
return profiles.currentProfile;
}, function(error) {
// Handle errors in either fetchServerConfig or
// fetchUserProfiles here
});
• Function calls are chained
• Functions called sequentially
• One error handler to rule them all
Angular Tools
Yeoman
• http://yeoman.io/
• Lets you generate a boiler plate with default structure
• Structure follows default conventions
• Base Config files are automatically generated
• Integration with Karma by default
• Integration with Test Runners
Karma
• http://karma-runner.github.io/0.10/index.html
• Easy to run tests
• Provide automated test cover
• Generates default specs
• Records test results
• Jasmine style specs
• Can understand angular natively
NG Boiler Plate
• http://joshdmiller.github.io/ng-boilerplate/#/home
• https://github.com/ngbp/ngbp#readme

• Another easy to use boiler plate with default dependencies
• Integrated with build system
• Pre Packed with Bootstrap, Font Awesome and Less
Angular UI
• http://angular-ui.github.io/
• Provides multiple extra components not natively part of
angular
• Pre packed with conventional usage components such as
highlighter, events not natively supported by angular and
indeterminate checkboxes etc
IDE
• http://www.jetbrains.com/webstorm/
• Paid with a 30 Day trial
• Only IDE I know with an angular JS plugin
• Code completion for angular directives
• Template completion shortcuts
• Browser watch for chrome
Batarang
• https://chrome.google.com/webstore/detail/angularjsbatarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en
• Chrome extension developed specifically for Angular JS

• Easy to debug angular scripts
• Identifies expensive bindings automatically

• Provides watch windows for service calls
• Easy to performance tune larger angular apps
Further Read
• http://docs.angularjs.org/api/
• http://docs.angularjs.org/tutorial/
• http://www.flipkart.com/mastering-web-applicationdevelopment-angularjs
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slidessamhelman
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginnersMunir Hoque
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0Nagaraju Sangam
 
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 jsMindfire Solutions
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)Gary Arora
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) PresentationRaghubir Singh
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
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 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Angular JS tutorial
Angular JS tutorialAngular JS tutorial
Angular JS tutorialcncwebworld
 

Was ist angesagt? (20)

Angular 4
Angular 4Angular 4
Angular 4
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
 
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
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
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 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Angular JS tutorial
Angular JS tutorialAngular JS tutorial
Angular JS tutorial
 

Andere mochten auch

Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular jsMustafa Gamal
 
Soa Runtime Governance Practices
Soa Runtime Governance PracticesSoa Runtime Governance Practices
Soa Runtime Governance PracticesMichiel.Kemperman
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
Space survival game
Space survival gameSpace survival game
Space survival gameRoss
 
How to Upgrade Angular 1 to Angular 2 - Piece by Piece
How to Upgrade Angular 1 to Angular 2 - Piece by Piece How to Upgrade Angular 1 to Angular 2 - Piece by Piece
How to Upgrade Angular 1 to Angular 2 - Piece by Piece Christopher T. Walrath
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
Building single page applications with angular.js
Building single page applications with angular.jsBuilding single page applications with angular.js
Building single page applications with angular.jsDieter De Mesmaeker
 
Migrating an Application from Angular 1 to Angular 2
Migrating an Application from Angular 1 to Angular 2 Migrating an Application from Angular 1 to Angular 2
Migrating an Application from Angular 1 to Angular 2 Ross Dederer
 
Embrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.xEmbrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.xLukas Ruebbelke
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-frameworkSakthi Bro
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Ross Dederer
 
Angular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationAngular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationEdureka!
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!Nir Kaufman
 
Angular 2 vs Angular 1
Angular 2 vs Angular 1Angular 2 vs Angular 1
Angular 2 vs Angular 1GDG Odessa
 
Living Things and Non-Living Things
Living Things and Non-Living ThingsLiving Things and Non-Living Things
Living Things and Non-Living Thingsgmanb5
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 

Andere mochten auch (20)

Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular js
 
Angular JS Introduction
Angular JS IntroductionAngular JS Introduction
Angular JS Introduction
 
Angular js
Angular jsAngular js
Angular js
 
Soa Runtime Governance Practices
Soa Runtime Governance PracticesSoa Runtime Governance Practices
Soa Runtime Governance Practices
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
Space survival game
Space survival gameSpace survival game
Space survival game
 
How to Upgrade Angular 1 to Angular 2 - Piece by Piece
How to Upgrade Angular 1 to Angular 2 - Piece by Piece How to Upgrade Angular 1 to Angular 2 - Piece by Piece
How to Upgrade Angular 1 to Angular 2 - Piece by Piece
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Building single page applications with angular.js
Building single page applications with angular.jsBuilding single page applications with angular.js
Building single page applications with angular.js
 
Migrating an Application from Angular 1 to Angular 2
Migrating an Application from Angular 1 to Angular 2 Migrating an Application from Angular 1 to Angular 2
Migrating an Application from Angular 1 to Angular 2
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 
Embrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.xEmbrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.x
 
Angular2 intro
Angular2 introAngular2 intro
Angular2 intro
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Angular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationAngular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page Application
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angular 2 vs Angular 1
Angular 2 vs Angular 1Angular 2 vs Angular 1
Angular 2 vs Angular 1
 
Living Things and Non-Living Things
Living Things and Non-Living ThingsLiving Things and Non-Living Things
Living Things and Non-Living Things
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 

Ähnlich wie Introduction to Angular JS

Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Community
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSDeepu S Nath
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Roy de Kleijn
 

Ähnlich wie Introduction to Angular JS (20)

Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
 
Angular
AngularAngular
Angular
 
Angular
AngularAngular
Angular
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Angularjs
AngularjsAngularjs
Angularjs
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails Webflow
 
mean stack
mean stackmean stack
mean stack
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS
AngularJSAngularJS
AngularJS
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 

Kürzlich hochgeladen

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Introduction to Angular JS

  • 1. An Introduction to a Powerful Framework Santhosh Kumar Github.com/santhotech
  • 2. What is Angular JS • A JavaScript framework (not for the faint hearted) • Simple to develop complex applications • Completely extensible • Extremely flexible • MVC Framework
  • 3. How is it different • Does not crave for control • Perfectly happy to work within your boundaries • Not greedy, can work with other libraries • Do not force you to use it mandatorily for your complete app • Lets you decide where its required and where its not
  • 4. When Should you use it • Scripts expanding at a rapid pace • Too many UI Bindings • Too many heavy lifting on the client side • Completely restful web applications • Single page web applications
  • 5. A Little Comparison JQuery Mark up: <input type=“text” id=“firstName” /> <div id=“firstNameBind”></div> Script: $(function(){ $("#firstName").keyup(function(){ $("#firstNameBind").html($("#firstName").val()); }); });
  • 6. Lets do it the angular way Angular Mark up: <input type=“text” ng-model=“rate.amount” /> <div>{{ rate.amount }}</div> Script: function OpController($scope) { $scope.rate = { amount: 0 } }
  • 7. Things to Note • Identifiers in the form of ID or Class or any other form is not required in Angular • Explicit bindings are not required • $scope is directly used without the need to create it • More natural syntax • Data driven
  • 8. Getting Started • Download the full/minified version of Angular from Angularjs.org <script src=“angular.js”></script> • Using Google CDN <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.x.x/angular.min.js"> </script>
  • 9. Specifying App Boundaries <html ng-app> <head> <title>Shopping Cart</title> <body > <div ng-controller='CartController'> <h1>Your Order</h1> <div>Total: {{bill.totalCart | currency}}</div> <div>Discount: {{bill.discount | currency}}</div> <div>Subtotal: {{bill.subtotal | currency}}</div> </div> </body> </html>
  • 10. Everywhere ng-app touches… • Ng-app specifies the overall boundary of the Application that will be used by angular • Ng-controller specifies the region that will be controlled by a specific controller
  • 11. $scope • $scope is an object that can be injected anywhere • Most data transitions happen through $scope • It does not have to be created or instantiated • It is available to be used directly through Angular dependency injection
  • 12. Dependency Injection • Objects are injected when ever it is required only at the time it is required • Lets you concentrate on important logic and not the dependencies that affect the behaviour • Angular is built completely on this principle • Law of Demeter • Principle of Least Knowledge
  • 13. $scope is not the chosen one • Many objects can be requested by adding it to the constructor • $scope is not the only one • $location, $route or even the directives we define can be requested via dependency injection by specifying in the constructor
  • 14. Events the Angular Way <form ng-submit="requestCash()" ngcontroller=“AccountController"> Amount: <input ng-change=“balanceCheckNeeded()" ngmodel=“currentDeposit"> Balance: {{availableBalance}} <button>Withdraw!</button> <button ng-click=”showLedger()">Ledger</button> </form>
  • 15. Hold your horses • Don’t hate declarative events • These are not the HTML events you are looking for • These are Angular Directives • No! We are not back to square one
  • 16. They are still unobtrusive • Cross Browser Compatibility • All heavy lifting done by angular • Events do not operate in global namespace • They work within their own scope of the parents controller
  • 17. Markup: <div class=“sectionbar" ng-controller=“SectionController"> … <li class="menu-item" ng-click="doSomeFunc()">Click Me</li> … </div> <div class="mainArea" ng-controller="MainAreaController"> … <div ng-click=" doSomeFunc()">...</div> … </div> Script: function SectionController($scope) { $scope.doSomeFunc = doA; } function MainAreaController($scope) { $scope.doSomeFunc = doB; }
  • 18. So that’s how it works • Mapping the right functions for the right events is automatically handled by Angular • No explicit directive other than the controller references is required • Declarative events reduce the hassle of fiddling with IDs and Classes • Still it doesn’t violate any best practices
  • 19. Modular Approach • Angular is completely modular • Namespaces allows perfect separation of application logic • Avoids need for conflict resolution in terms of similar objects
  • 20. <html ng-app='myApp'> <head> <title>Shopping Cart</title> <body > <div ng-controller=‘ShopController'> <h1>Your Order</h1> </div> </body> </html> Script: var myAppModule = angular.module('myApp',[]); myAppModule.controller(‘ShopController',function($scope){ $scope.menuState = { show : false}; });
  • 22. Ng-Repeat Mark up: <div ng-repeat='item in items'> <span>{{item.title}}</span> <input ng-model='item.quantity'> <span>{{item.price | currency}}</span> <span>{{item.price * item.quantity | currency}}</span> <button ng-click="remove($index)">Rfmove</button> </div> Script: myAppModule.controller('CartController', function($scope) { $scope.items = [ {title: 'Paint Pots1', quantity: 8, price: 3.95}, {title: 'Paint Pots2', quantity: 18, price: 12.95}, {title: 'Paint Pots3', quantity: 5, price: 6.95}, ]; });
  • 24. Double Curly Notation • Angular way of defining expression • May contain object references {{ account.balance }} • May point to variables which resolve to a value {{ myAccountBalance }} • May contain simple math expressions {{ currentTotal – accountBalance }}
  • 25. Note • • • • The values within double curly are not evaluated using eval They are evaluated by angular as special expression They cannot contain loops, conditional constructs They maintain state of the variable when there is a model binding
  • 26. Observer and Binding • $scope object called $watch • Once invoked keeps track of changes to an object • Can invoke a method when a change has been detected • Extremely useful to maintain object state when the object is modified from several different locations • Can watch an object, expression or a string that resolves to an object
  • 27. How it works myAppModule.controller(‘TaskController', function($scope) { $scope.tasks = { pendingTask: 0}; taskCompleted = function() { $scope.task.status = !$scope.task.isResolved; }; $scope.$watch(‘task.pendingTask', taskCompleted); }); • taskCompleted is invoked when ever there is a change in pendingTask • Change can effect from any source, direct or binded • Updates all binded dom elements automatically without explicit binding
  • 28. Usage Warning With great power comes great responsibility -Spiderman’s Uncle • While $watch seems like a powerful object (It really is) its usage must be checked • Watching wrong values may eat up the memory of the application • The expression provided must always be as less expensive as possible
  • 29. Communicating with the Server • Provides $http which contains $get, $post that can be used to communicate with web services • Both the underlying methods as well as the wrappers can be used • Transformations are provided for both request and response • Transformation can be intercepted • Provides interface to handle the XHR requests efficiently
  • 30. XHR has never been so easy $http.get('api/user', {params: {id: '5'} }).success(function(data, status, headers, config) { // Do something successful. }).error(function(data, status, headers, config) { // Handle the error }); Methods available for • GET • HEAD • POST • DELETE • PUT • JSONP
  • 31. Method Chaining with then var currentProfile = fetchServerConfig().then(function(serverConfig) { return fetchUserProfiles(serverConfig.USER_PROFILES, username); }).then(function(profiles) { return profiles.currentProfile; }, function(error) { // Handle errors in either fetchServerConfig or // fetchUserProfiles here }); • Function calls are chained • Functions called sequentially • One error handler to rule them all
  • 33. Yeoman • http://yeoman.io/ • Lets you generate a boiler plate with default structure • Structure follows default conventions • Base Config files are automatically generated • Integration with Karma by default • Integration with Test Runners
  • 34. Karma • http://karma-runner.github.io/0.10/index.html • Easy to run tests • Provide automated test cover • Generates default specs • Records test results • Jasmine style specs • Can understand angular natively
  • 35. NG Boiler Plate • http://joshdmiller.github.io/ng-boilerplate/#/home • https://github.com/ngbp/ngbp#readme • Another easy to use boiler plate with default dependencies • Integrated with build system • Pre Packed with Bootstrap, Font Awesome and Less
  • 36. Angular UI • http://angular-ui.github.io/ • Provides multiple extra components not natively part of angular • Pre packed with conventional usage components such as highlighter, events not natively supported by angular and indeterminate checkboxes etc
  • 37. IDE • http://www.jetbrains.com/webstorm/ • Paid with a 30 Day trial • Only IDE I know with an angular JS plugin • Code completion for angular directives • Template completion shortcuts • Browser watch for chrome
  • 38. Batarang • https://chrome.google.com/webstore/detail/angularjsbatarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en • Chrome extension developed specifically for Angular JS • Easy to debug angular scripts • Identifies expensive bindings automatically • Provides watch windows for service calls • Easy to performance tune larger angular apps
  • 39. Further Read • http://docs.angularjs.org/api/ • http://docs.angularjs.org/tutorial/ • http://www.flipkart.com/mastering-web-applicationdevelopment-angularjs