SlideShare a Scribd company logo
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

More Related Content

What's hot

Angular 4
Angular 4Angular 4
Angular 4
Saurabh Juneja
 
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 beginners
Munir Hoque
 
Angular js
Angular jsAngular js
Angular js
Dinusha Nandika
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju 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 js
Mindfire 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 - Introduction
Sagar Acharya
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
Tamer 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 concepts
Abhishek Sur
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
Raghubir Singh
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 
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
Stéphane Bégaudeau
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
Imtiyaz Ahmad Khan
 
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 2014
Sarah Hudson
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
Al-Mutaz Bellah Salahat
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
Yakov Fain
 
Angular JS tutorial
Angular JS tutorialAngular JS tutorial
Angular JS tutorial
cncwebworld
 

What's hot (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
 

Viewers also liked

Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular jsMustafa Gamal
 
Angular JS Introduction
Angular JS IntroductionAngular JS Introduction
Angular JS Introduction
Dhyego Fernando
 
Angular js
Angular jsAngular js
Angular js
ronhall13
 
Soa Runtime Governance Practices
Soa Runtime Governance PracticesSoa Runtime Governance Practices
Soa Runtime Governance Practices
Michiel.Kemperman
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
Oswald 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 & 2
Adam 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.js
Dieter 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
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
Mindfire Solutions
 
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
Lukas Ruebbelke
 
Angular2 intro
Angular2 introAngular2 intro
Angular2 intro
Shawn McKay
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
Sakthi 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 Application
Edureka!
 
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 1
GDG Odessa
 
Living Things and Non-Living Things
Living Things and Non-Living ThingsLiving Things and Non-Living Things
Living Things and Non-Living Things
gmanb5
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
Jesse Warden
 

Viewers also liked (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
 

Similar to Introduction to Angular JS

Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
Betclic Everest Group Tech Team
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
Filip Janevski
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
Santosh Kumar Kar
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
Damien Krotkine
 
Angular
AngularAngular
Angular
LearningTech
 
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
Reto Meier
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace
 
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 JS
Deepu S Nath
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
murtazahaveliwala
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf
 
mean stack
mean stackmean stack
mean stack
michaelaaron25322
 
Angular js
Angular jsAngular js
Angular js
Hritesh Saha
 
AngularJS
AngularJSAngularJS
AngularJS
LearningTech
 
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
Roy de Kleijn
 

Similar to 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
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

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