SlideShare une entreprise Scribd logo
1  sur  20
Your Cloud.
Your Business.
Advanced Angular Tips and Tricks
Jeremy Likness
Principal Architect
@JeremyLikness
www.ivision.com
TODAY’S AGENDA
1. Background Where did these tips and tricks come from?
2. Integration Tips for integrating existing JavaScript code
3. Best Practices Lessons learned in the trenches
4. Debugging Debugging Angular apps
5. Performance Writing Angular apps that scale and perform well
BACKGROUND
BACKGROUND
• Several Enterprise AngularJS Projects
• Largest Project:
• 80,000+ lines of TypeScript code (generated JavaScript even bigger)
• 100s of controllers, services, filters, and directives
• Global team of 25+ developers
• 2 years of development before go-live
• Exceeded client expectations for performance in most areas
• How much content have you read began with “I was tinkering
with…” or “I was exploring…”?
Lessons Learned
• It’s important you pick a code structure. There is no “best one” but it is
important to have one. We did:
/controllers
../common
../products
../customers
/directives
../common
../products
• Decouple from $scope as fast as you can!
• Don’t rely on $scope hierarchy/inheritance
• Use services for communication
• Use controller as syntax
• Maxim of Least Angular
• Test Early, and Test Often!
• For large teams, consider TypeScript
DEMO: Lessons Learned
INTEGRATION
INTEGRATION
• Register and reuse third-party components with Angular’s
dependency injection system
• Wrap third-party components to trigger digest
• Extend third-party components to be “Angular aware”
• Wrap third-party controls with Angular directives
• Create reusable libraries with Angular modules
• Consume third-party modules with Angular
DEMO: Integration
BEST PRACTICES
BEST PRACTICES
• $scope (addressed earlier)
• Use values (or constants) where it makes sense
• Wrap APIs in services and understand interceptors
• Use $log and $exceptionHandler
• Apply behaviors by decorating existing services with $provide
• Define code using Angular’s extend
• Lazy-load components with the injector when they aren’t
commonly used
• Use route’s “resolve” to guarantee asynchronous context
DEMO: Best Practices
DEBUGGING
DEBUGGING
• All major browsers provide F12 “debug tools”
• In Chrome, you can inspect/select an element and reference it as $0
• angular.element(x) wraps a DOM element as a node with Angular
functions e.g. angular.element($0)
• scope()
• isolateScope()
• controller()
• injector()
• Expand objects then navigate to source and set breakpoints/watches
• Batarang
DEMO: Debugging
PERFORMANCE
PERFORMANCE
• Batarang
• Zone to instrument
• Bindonce or new :: prefix
• Double-list approach
• ng-if vs. ng-show
• Measure twice, cut once!
DEMO: Performance
Questions?
Source for this deck
https://github.com/JeremyLikness/AngularTipsAndTricks
Running example for this deck
http://jeremylikness.github.io/AngularTipsAndTricks/
Mastering AngularJS Course: fundamentals, scope, digest, filters, dependency injection,
services, web services, routes, directives, testing, debugging and performance
https://www.wintellectnow.com/course/detail/mastering-angularjs
Jeremy Likness, Principal Architect @JeremyLikness

Contenu connexe

Tendances

Tendances (20)

Unit testing
Unit testingUnit testing
Unit testing
 
Building great spa’s with angular js, asp.net mvc and webapi
Building great spa’s with angular js, asp.net mvc and webapiBuilding great spa’s with angular js, asp.net mvc and webapi
Building great spa’s with angular js, asp.net mvc and webapi
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Latest Javascript MVC & Front End Frameworks 2017
Latest Javascript MVC & Front End Frameworks 2017Latest Javascript MVC & Front End Frameworks 2017
Latest Javascript MVC & Front End Frameworks 2017
 
Why Everyone else writes bad code
Why Everyone else writes bad codeWhy Everyone else writes bad code
Why Everyone else writes bad code
 
Demand driven applications with om.next and react native
Demand driven applications with om.next and react nativeDemand driven applications with om.next and react native
Demand driven applications with om.next and react native
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
 
How to build a JavaScript toolkit
How to build a JavaScript toolkitHow to build a JavaScript toolkit
How to build a JavaScript toolkit
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
Fast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCFast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVC
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
 
Frontend as a first class citizen
Frontend as a first class citizenFrontend as a first class citizen
Frontend as a first class citizen
 
AngularJS + React
AngularJS + ReactAngularJS + React
AngularJS + React
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)
 
What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013
 
Sharing the pain using Protractor
Sharing the pain using ProtractorSharing the pain using Protractor
Sharing the pain using Protractor
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
 

En vedette

Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 

En vedette (8)

Enterprise TypeScript
Enterprise TypeScriptEnterprise TypeScript
Enterprise TypeScript
 
Windows 8.1 Sockets
Windows 8.1 SocketsWindows 8.1 Sockets
Windows 8.1 Sockets
 
My XML is Alive! An Intro to XAML
My XML is Alive! An Intro to XAMLMy XML is Alive! An Intro to XAML
My XML is Alive! An Intro to XAML
 
The Windows Runtime and the Web
The Windows Runtime and the WebThe Windows Runtime and the Web
The Windows Runtime and the Web
 
Cross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team ServicesCross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team Services
 
Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.js
 
Angular 2 : learn TypeScript already with Angular 1
Angular 2 : learn TypeScript already with Angular 1Angular 2 : learn TypeScript already with Angular 1
Angular 2 : learn TypeScript already with Angular 1
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similaire à Advanced AngularJS Tips and Tricks

Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
Goutam Dey
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 

Similaire à Advanced AngularJS Tips and Tricks (20)

Angularjs
AngularjsAngularjs
Angularjs
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMS
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Angular js
Angular jsAngular js
Angular js
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
AngularJs Basic Concept
AngularJs Basic ConceptAngularJs Basic Concept
AngularJs Basic Concept
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Angular
AngularAngular
Angular
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Bhuvi ppt zerobug
Bhuvi ppt zerobugBhuvi ppt zerobug
Bhuvi ppt zerobug
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdf
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Dernier (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

Advanced AngularJS Tips and Tricks

  • 1. Your Cloud. Your Business. Advanced Angular Tips and Tricks Jeremy Likness Principal Architect @JeremyLikness
  • 3. TODAY’S AGENDA 1. Background Where did these tips and tricks come from? 2. Integration Tips for integrating existing JavaScript code 3. Best Practices Lessons learned in the trenches 4. Debugging Debugging Angular apps 5. Performance Writing Angular apps that scale and perform well
  • 5. BACKGROUND • Several Enterprise AngularJS Projects • Largest Project: • 80,000+ lines of TypeScript code (generated JavaScript even bigger) • 100s of controllers, services, filters, and directives • Global team of 25+ developers • 2 years of development before go-live • Exceeded client expectations for performance in most areas • How much content have you read began with “I was tinkering with…” or “I was exploring…”?
  • 6. Lessons Learned • It’s important you pick a code structure. There is no “best one” but it is important to have one. We did: /controllers ../common ../products ../customers /directives ../common ../products • Decouple from $scope as fast as you can! • Don’t rely on $scope hierarchy/inheritance • Use services for communication • Use controller as syntax • Maxim of Least Angular • Test Early, and Test Often! • For large teams, consider TypeScript
  • 9. INTEGRATION • Register and reuse third-party components with Angular’s dependency injection system • Wrap third-party components to trigger digest • Extend third-party components to be “Angular aware” • Wrap third-party controls with Angular directives • Create reusable libraries with Angular modules • Consume third-party modules with Angular
  • 12. BEST PRACTICES • $scope (addressed earlier) • Use values (or constants) where it makes sense • Wrap APIs in services and understand interceptors • Use $log and $exceptionHandler • Apply behaviors by decorating existing services with $provide • Define code using Angular’s extend • Lazy-load components with the injector when they aren’t commonly used • Use route’s “resolve” to guarantee asynchronous context
  • 15. DEBUGGING • All major browsers provide F12 “debug tools” • In Chrome, you can inspect/select an element and reference it as $0 • angular.element(x) wraps a DOM element as a node with Angular functions e.g. angular.element($0) • scope() • isolateScope() • controller() • injector() • Expand objects then navigate to source and set breakpoints/watches • Batarang
  • 18. PERFORMANCE • Batarang • Zone to instrument • Bindonce or new :: prefix • Double-list approach • ng-if vs. ng-show • Measure twice, cut once!
  • 20. Questions? Source for this deck https://github.com/JeremyLikness/AngularTipsAndTricks Running example for this deck http://jeremylikness.github.io/AngularTipsAndTricks/ Mastering AngularJS Course: fundamentals, scope, digest, filters, dependency injection, services, web services, routes, directives, testing, debugging and performance https://www.wintellectnow.com/course/detail/mastering-angularjs Jeremy Likness, Principal Architect @JeremyLikness