SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in AngularAlexe Bogdan
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - ServicesNir Kaufman
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introductionTania Gonzales
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor 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 SolutionsRapidValue
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core conceptsCodemotion
 
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 frameworkCodemotion
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0Nagaraju 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 AngularJSDavid Parsons
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 

Tendances (20)

Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Angular 5
Angular 5Angular 5
Angular 5
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Angular js
Angular jsAngular js
Angular js
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
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
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
 
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
 
Angular2
Angular2Angular2
Angular2
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
 
Angular js
Angular jsAngular js
Angular js
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 

En vedette

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

En vedette (9)

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

Similaire à AngularJS Fundamentals Guide

One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJSYashobanta Bai
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionOleksii Prohonnyi
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Arunangsu Sahu
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaphp2ranjan
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresherRavi Bhadauria
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesMohamad Al Asmar
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) PresentationRaghubir Singh
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Angularjs overview
Angularjs  overviewAngularjs  overview
Angularjs overviewVickyCmd
 

Similaire à AngularJS Fundamentals Guide (20)

AngularJS
AngularJS AngularJS
AngularJS
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: Introduction
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresher
 
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
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js Tutorials
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key Features
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Angular js
Angular jsAngular js
Angular js
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Angularjs overview
Angularjs  overviewAngularjs  overview
Angularjs overview
 

Plus de Eugene Fidelin

Testing: Do More With Less
Testing: Do More With LessTesting: Do More With Less
Testing: Do More With LessEugene 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 frontendsEugene Fidelin
 
Housekeeping the platform at scale
Housekeeping the platform at scaleHousekeeping the platform at scale
Housekeeping the platform at scaleEugene 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 frontendsEugene 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 7Eugene Fidelin
 
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.Eugene Fidelin
 

Plus de Eugene Fidelin (8)

Testing: Do More With Less
Testing: Do More With LessTesting: Do More With Less
Testing: Do More With Less
 
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
 
Housekeeping the platform at scale
Housekeeping the platform at scaleHousekeeping the platform at scale
Housekeeping the platform at scale
 
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
 
Безопасность Drupal сайтов
Безопасность Drupal сайтовБезопасность Drupal сайтов
Безопасность Drupal сайтов
 
Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.Разработка и deploy Drupal сайтов с помощью Features.
Разработка и deploy Drupal сайтов с помощью Features.
 
Работа с БД в Drupal 7
Работа с БД в Drupal 7Работа с БД в Drupal 7
Работа с БД в Drupal 7
 
Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.Фичи н-н-нада? Или почему стоит использовать модуль Features.
Фичи н-н-нада? Или почему стоит использовать модуль Features.
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

AngularJS Fundamentals Guide

  • 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