SlideShare a Scribd company logo
AngularJS
in
practice
Eugene Fidelin © 2015
VNU Vacature Media Image by redbubble.com
AngularJS
fundamentals Let me show you some
pictures ...
Core objects and concepts
Module
The highest-level Angular
object. Modules are how Angular
packages its code.
An Angular app as specified by
the ng-app directive always
corresponds to a module.
Other objects are always created
as children of modules.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
Config/Routes
Basically a container for app
setup.
Within config it's typical to
see routes configured. Routing
is a pairing a view with a
controller.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
Controller
Manages a special object called
a scope that is accessible by
the view that knows about that
controller.
The controller is the gateway
between the information that the
view sees, and the logic that
creates and works on that
information.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
Factory/Service/Provider
Places where data processing
should happen.
Each one is an Angular construct
that simply wraps a different
JavaScript approach to creating
objects.
With factory any other construct
could be created.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
Directive
The only place (besides the
view) where DOM manipulations
could be done.
Any time you find yourself
repeating chunks of HTML, or
referring to DOM nodes in
JavaScript code, create a
directive to encapsulate the
output.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
Filter
Let you package the
transformation of data in a way
that's usable with the | syntax
in the view.
For example, the expression
1408471200898 | date runs a
timestamp through the built-in
Angular date filter, outputting
Aug 19, 2014.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
View
Is the Angular-flavored HTML.
$scope lives between the view
and controller, and Angular is
making sure both ends of the app
have the latest version of it.
http://paislee.io/a-conceptual-introduction-to-angularjs
Directive
Filter
MVC interaction
http://www.slideshare.net/kmstechnology/building-singlepage-web-applications-with-angularjs
$scope
Two-way binding
http://devgirl.org/2013/03/21/fun-with-angularjs
Dependency injection
Each component explicitly
defined its dependencies.
Angular inject the requested
dependency by the function
argument names.
Once requested Angular’s
injector instantiates the
dependency and inject it.
angular.module('app', ['externalModule']);
angular.module('app')
.controller('MyController', function
($window, someOtherService) {
// ...
});
Bad practices I swear never to ...
Make code more
complicated, less reusable
and much harder to test.
Access or modify DOM in the controller
DOM should be changed only within the view (template) or
directive.
Use in the controller scope variables defined in the view
These variables (usually it is either form or form element)
should be explicitly passed to the controller methods.
Have business logic in the view
Views should have only render logic.
The rest should be either in the controller, filter or
directive (if you need to use more than 1 time).
Expression in view should be as simple as possible.
Use jQuery
If you are using jQuery to manipulate DOM - you don’t need
it. Angular has angular.element methods to manipulate the
DOM in the directive code.
Any other functionality of jQuery has appropriate
alternatives in Angular core or additional modules.
Perform HTTP requests in the controller
Controller should only use the services which encapsulate
HTTP requests and provides methods to use them.
Put any logic in the application module run method
If you need something that is global for the whole
application - create the service.
Use callbacks instead of promises
Promises are much easier to maintain and test - use them.
All asynchronous methods in Angular are returning promises,
so you are already using them.
Use a scalar variable within an isolated scope
Isolated scopes are created by multiple directives.Updates
from outside scopes won't appear inside after scalar
variable is changed inside.
Example: http://embed.plnkr.co/qRhLfw/preview
Note: using ControllerAs syntax solves the issue.
Good practices I’ll try my best to ...
Just make your life easier
and application more
reliable
Separate the Angular and backend templates
Use as less as possible Angular directives in the backend
templates.
ng-app and ng-controller to bootstrap Angular application
and and ng-include to inject the Angular views.
Use ng-bind instead of {{}}
The {{}} are much slower.
ng-bind is a directive and it will only apply, when the
passed value does actually change.
The brackets on the other hand will be dirty checked and
refreshed in every $digest, even if it's not necessary.
Also, unrendered brackets are visible to the user, what
required to use ng-cloak to hide them.
Use bind-once functionality
Angular allows to bind the value of an expression/attribute
once (will be bound when != ’undefined’). This is useful,
when value won’t be changed.
Place "::" before the binding to enable bind-once:
<p ng-bind=’::value’> or {{ ::value }}
Use ConrollerAs syntax
Controllers are more of a class
based - all variables are
assigned to this instead of
$scope.
Controllers are namespaced in
the views.
In details: Digging into
Angular’s “Controller as” syntax
app.controller('MainCtrl', function () {
this.title = 'Some title';
});
<div ng-controller="MainCtrl as main">
{{ main.title }}
</div>
Build tools
Grunt is our task runner,
let’s see what plugins are
used.
Help to write less code
and keep it clean,
automate the process.
grunt-contrib-jshint
Detects errors and potential problems in JavaScript code.
It is very flexible and can be easily adjusted to particular
coding guidelines and the environment where the code will be
executed
grunt-contrib-concat
Concatenates multiple JavaScript files into one to speed up
its downloading and page rendering.
Also allows to wrap code in the Immediately-Invoked Function
Expression (IIFE) that prevents you code from leaking into
the global scope.
grunt-ng-annotate
Adds and removes AngularJS dependency injection annotations.
It is non-intrusive so the source code stays exactly the
same otherwise.
Annotations are useful because with them it is possible to
minify the source code.
grunt-angular-templates
Speed up the AngularJS app by automatically minifying,
combining and caching HTML templates with $templateCache.
grunt-ng-constant
Separates code and configuration by dynamically generating
Angular constant modules from the json and yaml
configuration files.
grunt-contrib-uglify
Minifies and compress JavaScript files to minimize the size
of files that must be downloaded and improve page
performance.
Note: Angular dependency injection annotations should be
added before uglifying.
Testing A developer is known by
the tests he writes.
Angular is written with
testability in mind, but
it still requires that you
do the right thing.
Main tools
Karma is a JavaScript command line tool that can be used to
spawn a web server which loads your application's source
code and executes your tests.
Jasmine is a behavior driven development framework for
JavaScript. Provides functions to help with structuring
tests, making assertions and creating stubs (spies).
angular-mocks provides mocking for the tests. One of the
most useful parts is $httpBackend, which allows to mock XHR
requests in tests, and return sample data instead.
Unit tests
Angular comes with dependency injection built-in, which makes
testing much easier, because you can pass in a component's
dependencies and stub or mock them as you wish.
Test every controller, service or model in isolated
environment by mocking all non-core dependencies
(see Mocking Dependencies in AngularJS Tests)
Integration tests
Protractor is an end-to-end test framework for AngularJS
applications. Protractor runs tests against your application
running in a real browser, interacting with it as a user
would.
● Guide to AngularJS
Documentation
● AngularJS wiki
● A Conceptual Introduction
to AngularJS
● Sane, scalable Angular
apps are tricky, but not
impossible. Lessons
learned from PayPal
Checkout.
● Mocking Dependencies in
AngularJS Tests
Image by lifehack.org
Eugene Fidelin
Contacts
Email:
eugene.fidelin@gmail.com
Twitter:
@EugeneFidelin
Facebook:
facebook.com/eugene.fidelin
Github:
github.com/eugef

More Related Content

What's hot (20)

Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
Alexe Bogdan
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
Nir Kaufman
 
Angular 5
Angular 5Angular 5
Angular 5
Bartłomiej Narożnik
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
Keith Bloomfield
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Narek Mamikonyan
 
Angular js
Angular jsAngular js
Angular js
Knoldus Inc.
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
Bipin
 
AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
Tania Gonzales
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue SolutionsAngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
AngularJS
AngularJSAngularJS
AngularJS
Hiten Pratap Singh
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
Codemotion
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 
Angular2
Angular2Angular2
Angular2
Gabi Costel Lapusneanu
 
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
 
Angular js
Angular jsAngular js
Angular js
Dinusha Nandika
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
OrisysIndia
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
David Parsons
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
Sagar Acharya
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
Alexe Bogdan
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
Nir Kaufman
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
Bipin
 
AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
Tania Gonzales
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue SolutionsAngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
Codemotion
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 
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
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
OrisysIndia
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
David Parsons
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
Sagar Acharya
 

Viewers also liked (9)

Работа с материалами (nodes) в Drupal 7
Работа с материалами (nodes) в Drupal 7Работа с материалами (nodes) в Drupal 7
Работа с материалами (nodes) в Drupal 7
Eugene Fidelin
 
Работа с Views в Drupal 7
Работа с Views в Drupal 7Работа с Views в Drupal 7
Работа с Views в Drupal 7
Eugene Fidelin
 
Работа с полями (fields) в Drupal 7
Работа с полями (fields) в Drupal 7Работа с полями (fields) в Drupal 7
Работа с полями (fields) в Drupal 7
Eugene Fidelin
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practice
Eugene Fidelin
 
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Ontico
 
Lviv 2013 d7 vs d8
Lviv 2013   d7 vs d8Lviv 2013   d7 vs d8
Lviv 2013 d7 vs d8
Andy Postnikov
 
Многоязычие сайта на Drupal
Многоязычие сайта на DrupalМногоязычие сайта на Drupal
Многоязычие сайта на Drupal
Drupal Camp Kyiv
 
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Ontico
 
Работа с материалами (nodes) в Drupal 7
Работа с материалами (nodes) в Drupal 7Работа с материалами (nodes) в Drupal 7
Работа с материалами (nodes) в Drupal 7
Eugene Fidelin
 
Работа с Views в Drupal 7
Работа с Views в Drupal 7Работа с Views в Drupal 7
Работа с Views в Drupal 7
Eugene Fidelin
 
Работа с полями (fields) в Drupal 7
Работа с полями (fields) в Drupal 7Работа с полями (fields) в Drupal 7
Работа с полями (fields) в Drupal 7
Eugene Fidelin
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practice
Eugene Fidelin
 
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Дизайн REST API для высокопроизводительных систем / Александр Лебедев (Новые ...
Ontico
 
Многоязычие сайта на Drupal
Многоязычие сайта на DrupalМногоязычие сайта на Drupal
Многоязычие сайта на Drupal
Drupal Camp Kyiv
 
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Микросервисы: опыт использования в нагруженном проекте / Вадим Мадисон (М-Тех)
Ontico
 
Ad

Similar to AngularJS in practice (20)

Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
murtazahaveliwala
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJSCraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
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
 
AngularJS
AngularJS AngularJS
AngularJS
NexThoughts Technologies
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
Santosh Kumar Kar
 
Angularjs
AngularjsAngularjs
Angularjs
Ynon Perek
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
SolTech, Inc.
 
Angular js
Angular jsAngular js
Angular js
yogi_solanki
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
SC5.io
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJSCraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
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 Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
SC5.io
 
Ad

More from Eugene Fidelin (10)

Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Eugene Fidelin
 
Testing: do more with less (JSNation 2024)
Testing: do more with less (JSNation 2024)Testing: do more with less (JSNation 2024)
Testing: do more with less (JSNation 2024)
Eugene Fidelin
 
Testing: Do More With Less (AdvancedJS 2024)
Testing: Do More With Less (AdvancedJS 2024)Testing: Do More With Less (AdvancedJS 2024)
Testing: Do More With Less (AdvancedJS 2024)
Eugene Fidelin
 
Node.js BFFs - our way to the better/micro frontends
Node.js BFFs - our way to the better/micro frontendsNode.js BFFs - our way to the better/micro frontends
Node.js BFFs - our way to the better/micro frontends
Eugene Fidelin
 
Housekeeping the platform at scale
Housekeeping the platform at scaleHousekeeping the platform at scale
Housekeeping the platform at scale
Eugene Fidelin
 
Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontends
Eugene Fidelin
 
Безопасность Drupal сайтов
Безопасность Drupal сайтовБезопасность Drupal сайтов
Безопасность Drupal сайтов
Eugene Fidelin
 
Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.
Eugene Fidelin
 
Работа с БД в Drupal 7
Работа с БД в Drupal 7Работа с БД в Drupal 7
Работа с БД в Drupal 7
Eugene Fidelin
 
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Eugene Fidelin
 
Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Marko.js - Unsung Hero of Scalable Web Frameworks (DevDays 2025)
Eugene Fidelin
 
Testing: do more with less (JSNation 2024)
Testing: do more with less (JSNation 2024)Testing: do more with less (JSNation 2024)
Testing: do more with less (JSNation 2024)
Eugene Fidelin
 
Testing: Do More With Less (AdvancedJS 2024)
Testing: Do More With Less (AdvancedJS 2024)Testing: Do More With Less (AdvancedJS 2024)
Testing: Do More With Less (AdvancedJS 2024)
Eugene Fidelin
 
Node.js BFFs - our way to the better/micro frontends
Node.js BFFs - our way to the better/micro frontendsNode.js BFFs - our way to the better/micro frontends
Node.js BFFs - our way to the better/micro frontends
Eugene Fidelin
 
Housekeeping the platform at scale
Housekeeping the platform at scaleHousekeeping the platform at scale
Housekeeping the platform at scale
Eugene Fidelin
 
Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontends
Eugene Fidelin
 
Безопасность Drupal сайтов
Безопасность Drupal сайтовБезопасность Drupal сайтов
Безопасность Drupal сайтов
Eugene Fidelin
 
Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.
Eugene Fidelin
 
Работа с БД в Drupal 7
Работа с БД в Drupal 7Работа с БД в Drupal 7
Работа с БД в Drupal 7
Eugene Fidelin
 
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Eugene Fidelin
 

Recently uploaded (20)

Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 

AngularJS in practice

  • 1. AngularJS in practice Eugene Fidelin © 2015 VNU Vacature Media Image by redbubble.com
  • 2. AngularJS fundamentals Let me show you some pictures ... Core objects and concepts
  • 3. Module The highest-level Angular object. Modules are how Angular packages its code. An Angular app as specified by the ng-app directive always corresponds to a module. Other objects are always created as children of modules. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 4. Config/Routes Basically a container for app setup. Within config it's typical to see routes configured. Routing is a pairing a view with a controller. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 5. Controller Manages a special object called a scope that is accessible by the view that knows about that controller. The controller is the gateway between the information that the view sees, and the logic that creates and works on that information. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 6. Factory/Service/Provider Places where data processing should happen. Each one is an Angular construct that simply wraps a different JavaScript approach to creating objects. With factory any other construct could be created. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 7. Directive The only place (besides the view) where DOM manipulations could be done. Any time you find yourself repeating chunks of HTML, or referring to DOM nodes in JavaScript code, create a directive to encapsulate the output. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 8. Filter Let you package the transformation of data in a way that's usable with the | syntax in the view. For example, the expression 1408471200898 | date runs a timestamp through the built-in Angular date filter, outputting Aug 19, 2014. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 9. View Is the Angular-flavored HTML. $scope lives between the view and controller, and Angular is making sure both ends of the app have the latest version of it. http://paislee.io/a-conceptual-introduction-to-angularjs Directive Filter
  • 12. Dependency injection Each component explicitly defined its dependencies. Angular inject the requested dependency by the function argument names. Once requested Angular’s injector instantiates the dependency and inject it. angular.module('app', ['externalModule']); angular.module('app') .controller('MyController', function ($window, someOtherService) { // ... });
  • 13. Bad practices I swear never to ... Make code more complicated, less reusable and much harder to test.
  • 14. Access or modify DOM in the controller DOM should be changed only within the view (template) or directive.
  • 15. Use in the controller scope variables defined in the view These variables (usually it is either form or form element) should be explicitly passed to the controller methods.
  • 16. Have business logic in the view Views should have only render logic. The rest should be either in the controller, filter or directive (if you need to use more than 1 time). Expression in view should be as simple as possible.
  • 17. Use jQuery If you are using jQuery to manipulate DOM - you don’t need it. Angular has angular.element methods to manipulate the DOM in the directive code. Any other functionality of jQuery has appropriate alternatives in Angular core or additional modules.
  • 18. Perform HTTP requests in the controller Controller should only use the services which encapsulate HTTP requests and provides methods to use them.
  • 19. Put any logic in the application module run method If you need something that is global for the whole application - create the service.
  • 20. Use callbacks instead of promises Promises are much easier to maintain and test - use them. All asynchronous methods in Angular are returning promises, so you are already using them.
  • 21. Use a scalar variable within an isolated scope Isolated scopes are created by multiple directives.Updates from outside scopes won't appear inside after scalar variable is changed inside. Example: http://embed.plnkr.co/qRhLfw/preview Note: using ControllerAs syntax solves the issue.
  • 22. Good practices I’ll try my best to ... Just make your life easier and application more reliable
  • 23. Separate the Angular and backend templates Use as less as possible Angular directives in the backend templates. ng-app and ng-controller to bootstrap Angular application and and ng-include to inject the Angular views.
  • 24. Use ng-bind instead of {{}} The {{}} are much slower. ng-bind is a directive and it will only apply, when the passed value does actually change. The brackets on the other hand will be dirty checked and refreshed in every $digest, even if it's not necessary. Also, unrendered brackets are visible to the user, what required to use ng-cloak to hide them.
  • 25. Use bind-once functionality Angular allows to bind the value of an expression/attribute once (will be bound when != ’undefined’). This is useful, when value won’t be changed. Place "::" before the binding to enable bind-once: <p ng-bind=’::value’> or {{ ::value }}
  • 26. Use ConrollerAs syntax Controllers are more of a class based - all variables are assigned to this instead of $scope. Controllers are namespaced in the views. In details: Digging into Angular’s “Controller as” syntax app.controller('MainCtrl', function () { this.title = 'Some title'; }); <div ng-controller="MainCtrl as main"> {{ main.title }} </div>
  • 27. Build tools Grunt is our task runner, let’s see what plugins are used. Help to write less code and keep it clean, automate the process.
  • 28. grunt-contrib-jshint Detects errors and potential problems in JavaScript code. It is very flexible and can be easily adjusted to particular coding guidelines and the environment where the code will be executed
  • 29. grunt-contrib-concat Concatenates multiple JavaScript files into one to speed up its downloading and page rendering. Also allows to wrap code in the Immediately-Invoked Function Expression (IIFE) that prevents you code from leaking into the global scope.
  • 30. grunt-ng-annotate Adds and removes AngularJS dependency injection annotations. It is non-intrusive so the source code stays exactly the same otherwise. Annotations are useful because with them it is possible to minify the source code.
  • 31. grunt-angular-templates Speed up the AngularJS app by automatically minifying, combining and caching HTML templates with $templateCache.
  • 32. grunt-ng-constant Separates code and configuration by dynamically generating Angular constant modules from the json and yaml configuration files.
  • 33. grunt-contrib-uglify Minifies and compress JavaScript files to minimize the size of files that must be downloaded and improve page performance. Note: Angular dependency injection annotations should be added before uglifying.
  • 34. Testing A developer is known by the tests he writes. Angular is written with testability in mind, but it still requires that you do the right thing.
  • 35. Main tools Karma is a JavaScript command line tool that can be used to spawn a web server which loads your application's source code and executes your tests. Jasmine is a behavior driven development framework for JavaScript. Provides functions to help with structuring tests, making assertions and creating stubs (spies). angular-mocks provides mocking for the tests. One of the most useful parts is $httpBackend, which allows to mock XHR requests in tests, and return sample data instead.
  • 36. Unit tests Angular comes with dependency injection built-in, which makes testing much easier, because you can pass in a component's dependencies and stub or mock them as you wish. Test every controller, service or model in isolated environment by mocking all non-core dependencies (see Mocking Dependencies in AngularJS Tests)
  • 37. Integration tests Protractor is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would.
  • 38. ● Guide to AngularJS Documentation ● AngularJS wiki ● A Conceptual Introduction to AngularJS ● Sane, scalable Angular apps are tricky, but not impossible. Lessons learned from PayPal Checkout. ● Mocking Dependencies in AngularJS Tests Image by lifehack.org