SlideShare a Scribd company logo
AdvancedTipsand
Tricks using
AngularJS
SimonGuest,DistinguishedEngineer.
Neudesic,LLC
The lastdecade ofserver-side HTML...
Advanced Tips & Tricks for using Angular JS
What'swrongwiththis model?
What's wrongwiththis model?
Ā» Most UI actions require round trip
Ā» Poor mobile experience
Ā» Devices are getting more powerful
Ā» Servers need to scale
Ā» Any offline scenario is near impossible
The nextdecade ofclient-sideJavaScript
Advanced Tips & Tricks for using Angular JS
How doesthis help?
Ā» UI actions handled locally
Ā» Vasly improved mobile experience
Ā» Taking advantage of the power of the device
Ā» Server can handle more clients
Ā» Offline becomes more manageable
Too manychoices...
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
Audience Poll
Who knowswhatAngularJS is?
Who has builtAngularJS sample apps?
Who is usingAngularJS for an ongoing project?
Angular's ups and downs...
Advanced Tips & Tricks for using Angular JS
Goalofthis session
Share10tipsandtricksthatwe've
learnedfromrealworldAngularJS
projects
Goalofthis session
Compiledifferenttipsandtricksfrom
aroundtheWeb
Goalofthis session
Shareasmuchcodeaspossible
10. Structure
Howshould I structure my
AngularJS project?
10. Structure
Ā» Roll your own
Ā» Angular Seed (https://github.com/angular/angular-
seed)
Ā» Yeoman Angular Generator (http://yeoman.io)
Advanced Tips & Tricks for using Angular JS
10. Structure
Ā» Roll your own
Ā» Angular Seed (https://github.com/angular/angular-
seed)
Ā» Yeoman Angular Generator (http://yeoman.io)
10. Structure
Ā» Come back to pivoting on functionality when the
project gets large
10. Structure
> app
-> controllers
--> todoController.js
-> services
--> todoService.js
-> directives
--> todoItemDirective.js
10. Structure
> app
-> todo
--> controller.js
--> service.js
--> itemDirective.js
9. Minification
Should I minifymy
AngularJS project?
9. Minification
Ā» Due to the "DI" way that Angular works,
minification is hard
9. Minification
Ā» Due to the "DI" way that Angular works,
minification is hard
Ā» Do you really need to minify?
9. Minification
Ā» Due to the "DI" way that Angular works,
minification is hard
Ā» Do you really need to minify?
-- AngularJS includes are already compiled JS
-- Yeoman template includes as much minification
as you need
-- Disable property renaming, and manually change
constructors
8. Directives
Whatarethey?
8. Directives
Ā» They make AngularJS unique
Ā» They make your markup more declarative
Ā» They support templates nicely
Ā» They promote re-use
Ā» They prevent lots of JavaScript!
7. Page Loading
Howdo I createagood user
experience?
7. Page Loading
Ā» Flash of {{your.stuff}} when you load the page
7. Page Loading
Ā» Flash of {{your.stuff}} when you load the page
Ā» Use ng-cloak directive in order to hide
declarations until they are initialized
Ā» Use ng-bind instead of {{}} in your index.html
6. InternetExplorer
DoesAngularJSworkwith
IE?
Advanced Tips & Tricks for using Angular JS
6. InternetExplorer
Ā» Support for IE8 is being removed from Angular 1.3
onwards
Ā» If you are going to keep supporting IE8 with
Angular 1.2...
-- Never use <custom-directive>
-- Use <div custom-directive> instead
Ā» Ensure that IE is part of test plan (if you are
using Selenium)
5. Development
Environment
Whattools should I be
using?
5. DevelopmentEnvironment
Ā» Angular Support in IDEs
-- WebStorm 8
-- Sublime
-- Use data-ng-* in non-supported environments
Ā» Install Angular via Bower
5. DevelopmentEnvironment
Ā» Logging
-- Avoid using console.log in your controllers
Ā» Use $log instead
-- $log can be extended to provide additional
logging capabilities
5. DevelopmentEnvironment
Ā» Batarang
-- Chrome extension of AngularJS debugging
Advanced Tips & Tricks for using Angular JS
5. DevelopmentEnvironment
Ā» Batarang
-- Chrome extension to enable AngularJS debugging
Ā» AngularJS tab in Chrome dev tools
-- Enables scope inspection
-- Performance to identify trouble spots
-- Service dependency graph
5. DevelopmentEnvironment
Ā» Javascript Debugging
-- Use 'debugger' in any controller to add
breakpoint
-- Very useful combined with Batarang
4.Angular-
Supported
Frameworks
Howdo I dealwith non-
AngularJS stuff?
4. Non-Angular Stuff
Ā» Bootstrap
-- UI Bootstrap
-- Components written by the AngularJS team
Ā» Examples
-- AngularJS version of Alert
-- $modal for invoking modals
-- Date/time pickers
Ā» http://angular-ui.github.io/bootstrap/
Advanced Tips & Tricks for using Angular JS
4. Non-Angular Stuff
Ā» jQuery
-- Use angular.element instead of $() selector
-- Search for a jQuery-equivalent instead
Ā» Examples
-- html(), text(), val()
Ā» Ask whether you can use directives instead
4. Non-Angular Stuff
Ā» Other JavaScript methods
-- angular.fromJson, angular.toJson, angular.copy,
angular.extend
-- $timeout, $log, $window, $q, $document
-- Third party libraries for date formatting
Ā» Why?
-- Angular methods better observe the scope
lifecycle
-- More predictable results
3. Separation of
Concerns
Howdo I makethe right
choices?
3. Separation ofConcerns
Ā» Three golden rules
-- Controllers should never refer to any DOM
elements
-- Controllers should call services vs. holding
too much business logic
-- "How do I pass things between controllers?"
--- ...probably means that you are doing things
wrong
3. Separation ofConcerns
Ā» Controller inheritence
-- Is possible to use angular.extend to provide
some kind of inheritence on controllers
2. Scope
Whatdo I needto know
about$scope?
2. Scope
Ā» Scope is not your model
-- Even though many of the samples show it this
way
-- Scope should be the glue between your
controller and your model (accessed through
services)
-- Remember, services are singletons
2. Scope
Ā» Scope inheritence
-- Avoid $rootScope, try to use services instead
-- Create subscopes when invoking subcontroller
from controller
--- Can be a little confusing, especially with
frameworks (e.g. Bootstrap modal)
-- Batarang can be your friend
1. Performance
Howdo I prevent
performance bottlenecks?
1. Performance
Ā» You are not in control of when Angular invokes
functions based on changes to $scope
Ā» A single change in scope (e.g keypress) can call
multiple functions
1. Performance
Ā» Most changes to $scope are processed in fractions
of a second
-- Faster than the human eye can detect on a page
-- However, once you start reaching 1500+ function
calls on a scope change, thing's deteriorate
-- Deteriorate really quickly
1. Performance
Ā» Using ng-repeat or ng-switch can compound this
1. Performance
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td>{{item.description}}</td>
<td>{{getPrice(item.id)}}</td>
</tr>
Ā» How many times will getPrice function be called?
1. Performance
Ā» Overcoming this bottleneck
-- Never call $scope functions from within ng-
repeat or ng-switch statements
-- Use watch collection to calculate everyting
when the controller is first invoked
1. Performance
$scope.$watchCollection('items', function (newItems) {
for (var i = 0; i < newItems.length; i++) {
newItems[i].price = getPrice(newItems.id);
}
$scope.items = newItems;
});
1. Performance
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td>{{item.description}}</td>
<td>{{item.price}}</td>
</tr>
TheTenAgain
TheTenAgain
-- 10. Structure
-- 9. Minification
-- 8. Directives
-- 7. Page Loading
-- 6. Internet Explorer
-- 5. Development Environment
-- 4. Non-Angular Stuff
-- 3. Separation of Concerns
-- 2. Scope
-- 1. Performance
Thankyou!
Q&A
Ā» Simon Guest, Distinguished Engineer, Neudesic LLC
Ā» simonguest.com (@simonguest)
Ā» http://github.com/simonguest/gids
Ā» http://slideshare.net/simonguest
-- http://www.amazon.com/
File-New-Presentation-
Developers-Professionals/dp/
0615910459

More Related Content

PPTX
Introduction to Angularjs
Manish Shekhawat
Ā 
PPTX
Why angular js Framework
Sakthi Bro
Ā 
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
Ā 
PDF
AngularJS application architecture
Gabriele Falace
Ā 
PDF
AngularJS introduction
Tania Gonzales
Ā 
PDF
Introduction to AngularJS
Jussi Pohjolainen
Ā 
PPTX
The AngularJS way
Boyan Mihaylov
Ā 
PPTX
Angular js
Behind D Walls
Ā 
Introduction to Angularjs
Manish Shekhawat
Ā 
Why angular js Framework
Sakthi Bro
Ā 
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
Ā 
AngularJS application architecture
Gabriele Falace
Ā 
AngularJS introduction
Tania Gonzales
Ā 
Introduction to AngularJS
Jussi Pohjolainen
Ā 
The AngularJS way
Boyan Mihaylov
Ā 
Angular js
Behind D Walls
Ā 

What's hot (20)

ODP
AngularJs Crash Course
Keith Bloomfield
Ā 
PPTX
Angular JS - Introduction
Sagar Acharya
Ā 
PDF
AngularJS best-practices
Henry Tao
Ā 
PPTX
AngularJS Best Practices
Narek Mamikonyan
Ā 
PDF
AngularJS Basic Training
Cornel Stefanache
Ā 
PPTX
Angular js
Dinusha Nandika
Ā 
PDF
AngularJS Best Practices
Betclic Everest Group Tech Team
Ā 
PPTX
Understanding angular js
Aayush Shrestha
Ā 
PDF
AngularJS Framework
Barcamp Saigon
Ā 
PPTX
Practical AngularJS
Wei Ru
Ā 
PPTX
Angular js architecture (v1.4.8)
Gabi Costel Lapusneanu
Ā 
KEY
AngularJS for designers and developers
Kai Koenig
Ā 
PDF
AngularJS: an introduction
Luigi De Russis
Ā 
PDF
Angularjs architecture
Michael He
Ā 
PPTX
Angular js
Manav Prasad
Ā 
PPTX
AngularJs presentation
Phan Tuan
Ā 
PPTX
AngularJS in 60ish Minutes
Dan Wahlin
Ā 
PDF
AngularJS Basics and Best Practices - CC FE &UX
JWORKS powered by Ordina
Ā 
PPTX
AngularJS intro
dizabl
Ā 
PDF
AngularJS 101 - Everything you need to know to get started
StƩphane BƩgaudeau
Ā 
AngularJs Crash Course
Keith Bloomfield
Ā 
Angular JS - Introduction
Sagar Acharya
Ā 
AngularJS best-practices
Henry Tao
Ā 
AngularJS Best Practices
Narek Mamikonyan
Ā 
AngularJS Basic Training
Cornel Stefanache
Ā 
Angular js
Dinusha Nandika
Ā 
AngularJS Best Practices
Betclic Everest Group Tech Team
Ā 
Understanding angular js
Aayush Shrestha
Ā 
AngularJS Framework
Barcamp Saigon
Ā 
Practical AngularJS
Wei Ru
Ā 
Angular js architecture (v1.4.8)
Gabi Costel Lapusneanu
Ā 
AngularJS for designers and developers
Kai Koenig
Ā 
AngularJS: an introduction
Luigi De Russis
Ā 
Angularjs architecture
Michael He
Ā 
Angular js
Manav Prasad
Ā 
AngularJs presentation
Phan Tuan
Ā 
AngularJS in 60ish Minutes
Dan Wahlin
Ā 
AngularJS Basics and Best Practices - CC FE &UX
JWORKS powered by Ordina
Ā 
AngularJS intro
dizabl
Ā 
AngularJS 101 - Everything you need to know to get started
StƩphane BƩgaudeau
Ā 
Ad

Viewers also liked (7)

PPT
Codeigniter
minhrau111
Ā 
PDF
Building RESTtful services in MEAN
Madhukara Phatak
Ā 
PDF
Top 100 PHP Questions and Answers
iimjobs and hirist
Ā 
PPTX
CodeIgniter 101 Tutorial
Konstantinos Magarisiotis
Ā 
PDF
Javascript Best Practices
Christian Heilmann
Ā 
PPTX
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
Ā 
PPT
PHP - Introduction to PHP MySQL Joins and SQL Functions
Vibrant Technologies & Computers
Ā 
Codeigniter
minhrau111
Ā 
Building RESTtful services in MEAN
Madhukara Phatak
Ā 
Top 100 PHP Questions and Answers
iimjobs and hirist
Ā 
CodeIgniter 101 Tutorial
Konstantinos Magarisiotis
Ā 
Javascript Best Practices
Christian Heilmann
Ā 
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
Ā 
PHP - Introduction to PHP MySQL Joins and SQL Functions
Vibrant Technologies & Computers
Ā 
Ad

Similar to Advanced Tips & Tricks for using Angular JS (20)

PDF
AngularJS in practice
Eugene Fidelin
Ā 
PPTX
Intro to AngularJs
SolTech, Inc.
Ā 
PDF
AngularJS Basics
Ravi Mone
Ā 
PPTX
Angular workshop - Full Development Guide
Nitin Giri
Ā 
PPT
Angular js
yogi_solanki
Ā 
PDF
AngularJS: Overview & Key Features
Mohamad Al Asmar
Ā 
PDF
AngularJS 101
Houssem Yahiaoui
Ā 
PDF
[Ebooks PDF] download AngularJS 1st Edition Brad Green full chapters
kiciunonge
Ā 
PPTX
AngularJS.part1
Andrey Kolodnitsky
Ā 
PPTX
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
Ā 
PDF
AngularJS Workshop
Gianluca Cacace
Ā 
PDF
Tips from angular js users anonymous
Oleg Podsechin
Ā 
PPT
Angular js
Hritesh Saha
Ā 
PDF
Download full ebook of Angularjs Brad Green Shyam Seshadri instant download pdf
mehiicniode
Ā 
PDF
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
vivaanpulcha
Ā 
PDF
Pavlo Yuriychuk — Switching to Angular.js. Silk way
GlobalLogic Ukraine
Ā 
PDF
Switching to angular.js silk way
Pavlo Iuriichuk
Ā 
PPTX
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
Ā 
PPTX
Training On Angular Js
Mahima Radhakrishnan
Ā 
PDF
Everything You Need To Know About AngularJS
Sina Mirhejazi
Ā 
AngularJS in practice
Eugene Fidelin
Ā 
Intro to AngularJs
SolTech, Inc.
Ā 
AngularJS Basics
Ravi Mone
Ā 
Angular workshop - Full Development Guide
Nitin Giri
Ā 
Angular js
yogi_solanki
Ā 
AngularJS: Overview & Key Features
Mohamad Al Asmar
Ā 
AngularJS 101
Houssem Yahiaoui
Ā 
[Ebooks PDF] download AngularJS 1st Edition Brad Green full chapters
kiciunonge
Ā 
AngularJS.part1
Andrey Kolodnitsky
Ā 
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
Ā 
AngularJS Workshop
Gianluca Cacace
Ā 
Tips from angular js users anonymous
Oleg Podsechin
Ā 
Angular js
Hritesh Saha
Ā 
Download full ebook of Angularjs Brad Green Shyam Seshadri instant download pdf
mehiicniode
Ā 
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
vivaanpulcha
Ā 
Pavlo Yuriychuk — Switching to Angular.js. Silk way
GlobalLogic Ukraine
Ā 
Switching to angular.js silk way
Pavlo Iuriichuk
Ā 
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
Ā 
Training On Angular Js
Mahima Radhakrishnan
Ā 
Everything You Need To Know About AngularJS
Sina Mirhejazi
Ā 

More from Simon Guest (20)

PDF
10 Life Hacks for Better Productivity
Simon Guest
Ā 
PDF
Building a Great Engineering Culture
Simon Guest
Ā 
PDF
Interviewing Techniques
Simon Guest
Ā 
PDF
Presentation Anti-Patterns
Simon Guest
Ā 
PDF
10 Life Hacks for Better Productivity
Simon Guest
Ā 
PDF
Automated Web Testing using JavaScript
Simon Guest
Ā 
PDF
Indoor location in mobile applications using iBeacons
Simon Guest
Ā 
PPTX
Creating Context-Aware Applications
Simon Guest
Ā 
PPTX
Automated Testing using JavaScript
Simon Guest
Ā 
PDF
Enterprise Social Networking - Myth or Magic?
Simon Guest
Ā 
PPTX
Objective View of MEAPs
Simon Guest
Ā 
PPTX
Top Ten Tips for HTML5/Mobile Web Development
Simon Guest
Ā 
PPTX
Windows Azure Toolkit for iOS
Simon Guest
Ā 
PPTX
Developing Enterprise-Grade Mobile Applications
Simon Guest
Ā 
PPTX
My customers are using iPhone/Android, but I'm a Microsoft Guy.
Simon Guest
Ā 
PPTX
Developing iPhone and iPad apps that leverage Windows Azure
Simon Guest
Ā 
PPTX
iPhone and iPad Security
Simon Guest
Ā 
PPTX
Building solutions on the Microsoft platform that target iPhone, iPad, and An...
Simon Guest
Ā 
PPTX
Future of Mobility
Simon Guest
Ā 
PDF
Patterns for Cloud Computing
Simon Guest
Ā 
10 Life Hacks for Better Productivity
Simon Guest
Ā 
Building a Great Engineering Culture
Simon Guest
Ā 
Interviewing Techniques
Simon Guest
Ā 
Presentation Anti-Patterns
Simon Guest
Ā 
10 Life Hacks for Better Productivity
Simon Guest
Ā 
Automated Web Testing using JavaScript
Simon Guest
Ā 
Indoor location in mobile applications using iBeacons
Simon Guest
Ā 
Creating Context-Aware Applications
Simon Guest
Ā 
Automated Testing using JavaScript
Simon Guest
Ā 
Enterprise Social Networking - Myth or Magic?
Simon Guest
Ā 
Objective View of MEAPs
Simon Guest
Ā 
Top Ten Tips for HTML5/Mobile Web Development
Simon Guest
Ā 
Windows Azure Toolkit for iOS
Simon Guest
Ā 
Developing Enterprise-Grade Mobile Applications
Simon Guest
Ā 
My customers are using iPhone/Android, but I'm a Microsoft Guy.
Simon Guest
Ā 
Developing iPhone and iPad apps that leverage Windows Azure
Simon Guest
Ā 
iPhone and iPad Security
Simon Guest
Ā 
Building solutions on the Microsoft platform that target iPhone, iPad, and An...
Simon Guest
Ā 
Future of Mobility
Simon Guest
Ā 
Patterns for Cloud Computing
Simon Guest
Ā 

Recently uploaded (20)

PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
PDF
Software Development Methodologies in 2025
KodekX
Ā 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
Ā 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
Ā 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
PDF
Software Development Company | KodekX
KodekX
Ā 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
Ā 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
Ā 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
Software Development Company | KodekX
KodekX
Ā 

Advanced Tips & Tricks for using Angular JS