SlideShare a Scribd company logo
1 of 80
Download to read offline
AngularJs Best Practices
• File Organization
• Namespacing and File naming
• Understanding Modules
• Organizing modules
• Minification
• Definitions and roles
• Controllers
• Services
• Directives
• Scope
• Communicating between components
• Avoiding FOUC
• Thinking Declaratively
• Directives as a DSL
• Breaking Down A Page into Components
• $resource
• Restangular
• Betclic best practices
• Conclusion
Agenda
Note: all screenshots are copyright from their respective owners.
• Basic
Only for a small POC app
3
File Organization
• By feature
4
File Organization
• By feature then type
If more than 15 files , split by type
Don’t forget that the file
organization doesn’t reflect how
code is delivered
5
File Organization
• Miror app file organization for unit test
• Keep same file name + ‘Test’
6
File Organization
• Why naming ?
– Object type reading
– Avoid collisions (silent with Ajs!)
7
Namespacing and File naming
• NameSpacing solution (2 or 3 letters pre-fix) :
8
Namespacing and File naming
• Controllers : ScheduleCtrl
• Services : ScheduleSvc
• Filters : RatingFilter
• Directives : small-schedule
• Partials :
– if my controller is ScheduleCtrl  ScheduleCtrl.html
– If my directives is small-schedule  small-schedule.html
9
Namespacing and File naming
10
Understanding Modules
• Modules have nothing to do
with object naming (so far…)
• The Injector has the list of all
the objects in our application
• Only one injector exists in each
Angular application
11
Understanding Modules
Modules
• One Module
+ it's the simplest option by far
you don't have to worry about how your module organization reflects the
organization of your files and folders, and you still only need to deliver the code
you want running in the browser.
- if you have code that you are sharing amongst several applications, then they
all need to have the same module name.
- delivering code as a third party or publishing it to the open source community
is not really a possibility.
12
Organizing modules
• Two Modules
One for code custom to the current application, and one for any shared code.
+ simplicity
- increased complexity, and some rigidity when sharing or publishing code.
This strategy works best if you will be building multiple applications that may
share some code, or if you intend to publish a portion of your code to third
parties, or you plan to open source it, say a library of widgets.
13
Organizing modules
• MainModule with several sub-modules
The MainModule may or may not have any actual objects in it, it might just be a
collection of sub-modules.
+ you have tons of organization for your code
Modules become an extra way to organize and deliver just the parts of your
application that you want to deliver.
- increased complexity of managing those different modules.
- build system will have to be more complex as well
14
Organizing modules
var servicesA = angular.module('servicesA', []);
var servicesB = angular.module('servicesB', []);
var serviceApp = angular.module('serviceApp', ['servicesA‘, 'servicesB']);
15
MainModule with several sub-modules
Example
• removing all unnecessary whitespace
• rename variables and parameters to short names.
Problem : Angular uses reflection to look at parameter names of certain
functions like controllers and services, so that its dependency injector can
provide the correct dependency
angular.module('app').controller('Controller1',function($scope, mySvc) {
$scope.val = mySvc.val;
})
.NET bundling 
angular.module('app').controller('Controller1',function(a, b) {
a.val = b.val;
})
16
Minification
• Node solution : ng-min
• Our solution : classic .net bundling on fly
Constraints , we need to write that way:
angular.module('app').controller('Controller1',
['$scope','mySvc', function($scope, mySvc) { $scope.val = mySvc.val;}])
I
17
Minification
• Controllers
– setup the scope
– view interaction
• Services
– handle non-view logic
– communicate with the server
– hold data & state (not the only one)
– DOM manipulation (code smell ;))
– Business
• Directives
– Manipulate DOM
– Receive View Events
18
Definitions and roles
• Views
– Display the application
– Declare bindings & directives
• coordinate View and Model
Nothing else, the ctrl shouldn’t knwon the business logic or the model structure
angular.module('app').controller('scheduleCtrl',function($scope, schedule) {
$scope.schedule = schedule;
$scope.register = function(newClass) {
$scope.schedule.register(newClass);
}
});
• Limited # of collaborators
 split the ctrl in smaller ones
 Facade pattern
• Testable 19
Controllers – Design guidelines
A service is treated as a singleton, that is there is only one instance of a
specific service available during the whole lifetime of the Angular application.
This is different from e.g. a controller of which many instances can be created.
app.service(‘registration’, function() {
return {
title: ‘Service from Service’
}
});
But in Angular there are actually sevral ways to create a service
20
Services - creation
app.value(‘myValService’, ‘someValue’);
What the value function does is create a service that is exactly what you
passed into the value function.
We can define any string, number, date-time, array or object as a value. We
can even register a function as a value
This could be things like the full name of the user, it’s role and so on. Typically
we would load this data after the user has successfully logged into the system
and keep this data around as long as the user remains logged in.
Dependancy Injection is not possible.
21
Services –value
The constant function is essentially the same as the value function, except it's
available during the app configuration phase.
app.constant(‘myValService’, ‘someValue’);
The difference between a value and a constant service is that the former can
only be injected (and thus be used) in a service or a controller while the latter
can also be injected into a module configuration function..
Dependancy Injection is not possible.
22
Services – constant
Example
app.constant(‘myValService’, ‘someValue’);

var app = angular.module('app', []);
app.config(function ($provide) {
$provide.constant('movieTitle', 'The Matrix');
});
app.controller('ctrl', function (movieTitle) {
expect(movieTitle).toEqual('The Matrix');
});
23
Services – constant
The purpose of the factory function is to generate the single object, or function,
that represents the service to the rest of the application.
app.factory('profile', function() {
return {
"name": "Anonymous",
"Id": null,
"login": function(){…},
"logout": function(){…}
}
});
So the factory function is simply just the normal way to create a service.
Notice that the factory function can ask for other dependencies.
24
Services - factory
The service function is a lot like the factory function with one difference.
The service function will take the function you give it and call new on it. Then it
will cache the result of that function and give you the result every time you ask
for that service.
monApp.service('profile', function() {
this.name = "Anonymous";
this.id = null;
this.login = function(){…}
this.logout = function(){…}
});
« return » isn’t required.
Generally factory is all you need. No question regarding the “this” ! 25
Services - service
This function is ultimately what all those other functions use under the covers.
This allows you to create a service from a much lower level.
What you have to do is give the provider function another function whose return
value must have a $get function.
A provider is actually a configurable factory. The provider accepts an object or
a constructor.
The benefit here is that using provider, you have the option to make your
service configurable and configure it before it is created.
Offical Reco :
You should use the Provider recipe only when you want to expose an API for
application-wide configuration that must be made before the application starts.
This is usually interesting only for reusable services whose behavior might
need to vary slightly between applications. 26
Services - provider
angular.module('app').controller('scheduleCtrl',function($scope, registration) {
$scope.title = registration.title;
});
app.config(function($provide) {
$provide.provider('registration', function() {
var type;
return {
setType: function(value) {
type = value;
},
$get: function() {
return {
title: 'Service from Provider ' + type
}
} } })})
app.config(function(registrationProvider) {
registrationProvider.setType('Angular');
})
27
Services - provider
A decorator can modify or encapsulate other providers. There is one exception
and that a constant cannot be decorated
28
Services - Decorator
var app = angular.module('app', []);
app.value('movieTitle', 'The Matrix');
app.config(function ($provide) {
$provide.decorator('movieTitle', function ($delegate) {
return $delegate + ' - starring Keanu Reeves';
});
});
app.controller('myController', function (movieTitle) {
expect(movieTitle).toEqual('The Matrix - starring Keanu Reeves');
});
Filters are really just a service with a specific kind of name.
29
Services – filters as services
app.factory("ratingsFilter", function() {
return function(input) {
var rating = parseInt(input);
var result = "";
for(var i=0; i < rating; i++) {
result += "*";
}
return result;
}
});
app.filter("ratings", function() {
return function(input) {
var rating = parseInt(input);
var result = "";
for(var i=0; i < rating; i++) {
result += "*";
}
return result;
}
});
• SRP : single responsability !
• Cohesive : having all the functionality of an object relate to the primary
purpose of the object
• Loosely Coupled : A good service should be loosely coupled to any
dependencies that it has.
• Good interface : Any situation where you call multiple methods to do a
single job is less effective.
• Testable
30
Services – Design Guidelines
function Course(title, instructorIds, id) {
this.title = title;
this.instructorIds = instructorIds;
this.id = id;
}
Course.prototype.displayName = function() {
// code
}
…
app.value('courseFactory', {
createCourse: function(title, credits, department, instructors) {
var instructorIds = [];
for(var i=0; i < instructors.length; i++) {
instructorIds.push(instructors[i].id);
}
return new Course(title, instructorIds, -1);
}
}) 31
Services - Specific Types - Factories
app.value('schedule', {
classes: [],
addClass: function(newClass) {
for(var i=0; i < this.classes.length; i++) {
if(this.classes[i] === newClass) {
return;
}
}
this.classes.push(newClass);
},
dropClass: function(classToDrop) {
for(var i=0; i < this.classes.length; i++) {
if(this.classes[i] === classToDrop) {
this.classes.splice(i, 1);
}
}
}
}) 32
Services - Specific Types - Stateful Singletons
app.value('grades', []);
app.value('calculateGPA', function(grades) {
// implementation
return "4.0";
})
app.controller('userCtrl',function($scope, grades, calculateGPA) {
$scope.GPA = calculateGPA(grades);
});
33
Services - Specific Types - Functions
• Services
Syntax: module.service( 'serviceName', function );
Result: When declaring serviceName as an injectable argument you will be
provided with an instance of the function. In other words new
FunctionYouPassedToService().
• Factories
Syntax: module.factory( 'factoryName', function );
Result: When declaring factoryName as an injectable argument you will be
provided with the value that is returned by invoking the function reference
passed to module.factory.
• Providers
Syntax: module.provider( 'providerName', function );
Result: When declaring providerName as an injectable argument you will be
provided with ProviderFunction().$get(). The constructor function is
instantiated before the $get method is called - ProviderFunction is the function
reference passed to module.provider. 34
Services - Summary
• Purposes of directives
piece of visible display that may or not be reusable, but whose functionality is
encapsulated and an interface provided so that the widget can easily represent
a piece of display and functionality of your app
• Classic Error :
In The javascript : myDirective (CamelCase)
In the view : my-directive (snake case)
 First thing to check in case of error : check the names 
• Naming Convention: prefix : bc/bcsp ?
A directive should be unique because Ajs doesn’t override, but stack.
35
Directives
JS:
app.directive(‘bcHelloWorld', function() {
return {
restrict: 'E',
replace: 'true',
template: '<h3>Hello World!!</h3>'
};
});
Html:
<bc-hello-world/>
36
Directives
• restrict: 'E' => Element : <date-picker></date-picker>
• restrict: ‘A' => Attributes: <input type="text" date-picker/>
• restrict: 'C' => class : <input type="text" class="date-picker"/>
• restrict: 'M' => comment : <!--directive:date-picker-->
Combine possible, for example : restrict: 'AE‘
Html5 compliant : <input type="text" data-date-picker/>
37
Directives - restrict
• Template : inline
• TemplateUrl : path to html file
38
Directives – template / templateUrl
True :
<h3>Hello World!!</h3>
False:
<hello-world><h3>Hello World!!</h3></hello-world>
39
Directives – replace
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: true,
template: '<p style="background-color:{{color}}">Hello World',
link: function(scope, elem, attrs) {
elem.bind('click', function() {
elem.css('background-color', 'white');
scope.$apply(function() {
scope.color = "white";
});
});
elem.bind('mouseover', function() {
elem.css('cursor', 'pointer');
});
}
}; 40
Directives – Link
It takes three arguments:
• scope – The scope passed to the directive. In this case it’s the same as the
parent controller scope.
• elem – The jQLite (a subset of jQuery) wrapped element on which the
directive is applied. If you have included jQuery in the HTML before
AngularJS is included, this becomes jQuery wrapped instead of jQLite. As
the element is already wrapped with jQuery/jQLite, there is no need to again
wrap it inside $() for DOM manipulations.
• attrs – An object representing normalized attributes attached to the element
on which the directive is applied. For example, you can attach attributes in
HTML like: <hello-world some-attribute></hello-world> and access it in
the link function as attrs.someAttribute.
41
Directives – Link
return {
restrict:'E',
require: 'nameOfSiblingController'
}
Ability to require in a controller from another directive,
Return null if the required isn’t here.
Require on parent :
return {
restrict:'E',
require: '^nameOfParentController'
}
42
Directives – Require
2 solutions :
• put the functionality into the link function of the directive
• create a controller and put that functionality into the controller (can be no
inline to reuse it)
controller: function($scope) {
$scope.viewClassDetails = function(classToView) {
// do something
console.log('viewing details for ' + classToView.name);
}
<=>
link: function(scope) {
scope.viewClassDetails = function(classToView) {
// do something
console.log('viewing details for ' + classToView.name);
}
}
43
Directives - Controllers vs Link
Ask yourself “when do I want my code to run?”
Before compilation? – Controller
After compilation? – Link
 Never condone putting DOM manipulation in an angular controller
“Am I just doing template and scope things?” – goes into controller
“Am I adding some coolbeans jquery library?” – goes in link
http://jasonmore.net/angular-js-directives-difference-controller-link/
44
Directives - Controllers vs Link
there are 3 ways for a directive to interface with a containing scope:
1. share the scope
2. create an inherited scope
3. create an isolated scope
1&2 : the directive simply has access to all the objects in the containing scope
Stop !!!! What is the scope ??
45
Directives - interfaces
In Angular, the scope is the magic. All binding happens through a scope, all
interaction happens through a scope.
 very important to understand
Help to debug : chrome extension « AngularJS Batarang »
1. on top i have the root scope / ng-app correspond to the root scope
2. all scopes belong to exactly 1 Element
3. 1 scope <=> 1 ng-controller
46
Scope - Dealing with scope
47
Scope - Dealing with scope
• By default
48
Scope - Sharing scope
app.directive('scInstructorCount', function() {
return {
scope: true,
link: function(scope) {
scope.instructorList.push({id:4, name: 'Professor Lockhart'});
scope.CurrentInstructorId = 22;
}
}
});
Example : only the directive see the CurrentInstructorId
49
Scope - inherited scope
WARING EASY BUG !!
how do you correctly bind an ngModel to a parent scope item
=> make sure there is a dot in the binding
50
Scope - inherited scope
app.directive('scInstructorCount', function() {
return {
restrict: 'A',
replace: true,
templateUrl: 'scInstructorCount.html',
scope: {
instructorList: '=',
title: '='
},
link: function(scope) {
scope.title = "My New Title";
}
}
});
<div sc-instructor-count instructor-list="instructorList" title="title" sc-new-
instructor></div>
51
Scope - Isolating scope
WARNING
snake-case / camel-
case
Two way binding !
+ : easy
- : hidden dependencies
- : put things in the parent useless for him, here only for the childs
52
Communicating between components
Communicating with Inherited Scopes
• Use global bus:
$rootScope.$broadcast("course:registered", course);

$scope.$on('course:registered', function(event, course) {
$scope.notify('You have registered for ' + course.name);
})
+ : logic, responsability inside the ctrl
- : add $rootscope to every listeners, a listener could cancel the event
- : warning to the string name of the event
53
Communicating between components
Communicating with Events
A service is a singleton so it’s the same for every body.
+ : business logic is in the right place
- : more set-up work
- : difficult to draw the line between display logic and business logic
54
Communicating between components
Communicating with Services
I see dead brackets !!!!
It happen more for classic website, not for SPA.
Solution 1: ngCloak
Need to add style in css :
[ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}
We add the directive ngCloak on the place we want to hide before the binding (
not too high, to not display too much white space)
55
Avoiding FOUC
Flash of Unstyled Content
Solution 2: ngBind
<h1>{{name}}</h1>

<h1 ng-bind="name">&nbsp;</h1>
But we still have a problem with ng-hide, which hide nothing until the binding,
56
Avoiding FOUC
Flash of Unstyled Content
Solution 3: Waiting image
<img src="spinner.gif" ng-hide="ready" style="width:400px" />
<div ng-cloak ng-show="ready" class="jumbotron">..</div>
The « ready » variable is set to true when the data are loaded,
57
Avoiding FOUC
Flash of Unstyled Content
old way : write Html, write Jquery to manipulate the DOM
Angular Way:
• Put declarative View Logic in the View
• Don't put imperative logic in the view
 imperative code belongs in the controller, declarative code belongs in the
view
Thinking about how to do something with the view might lead us down the
wrong road
Thinking declaratively,what we want to do is represent our state in our
controller and then get the view to manipulate itself based on that state.
The controler should not take control of the view but the view should listen to
the scope !
 clean code.
58
Thinking Declaratively
create custom HTML through directives
 not only powerful, it is truly paradigm changing when it comes to web
development
your HTML turn a low-level description of the layout of a web page into a
domain-specific language that describes the functionality of your application
 Primary type to object !
 HTML not only technic, it has to be readable !
59
Directives as a DSL
• Inline controllers (only js)
• Controllers and ngInclude (html)
• Directives (js + html)
60
Breaking Down A Page into Components
• Manage deferred tasks (e.g. asynchronous tasks)
• Methods
– then(successCallback, errorCallback, notifyCallback): callback for successfully
resolved promise, callback for error (optional), and notify (optionnal, see
« deferred »)
– catch(errorCallback): callback for error
– finally(callback): callback for either success or error but with no data
modification (?)
• Promises can be chained.
61
Promises
• Creates and manipulates a promise
• Methods:
– resolve(value): ends the promise (success) with the given value
– reject(reason): same but with an error
– notify(value): updates promise without ending it
• Promise : property that gives the associated promise object
• $q (injectable)
– create a deferred object: $q.defer()
– Method “all”: Use to combine multiple promises into a single one (resolved when
all promises are resolved; rejected when any promise is rejected),
62
Deferred
• Factory AngularJS to interact with RESTful APIs
• Module: ‘ngResource’
• Basic usage:
• Returns object with defaults methods:
{
'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
}
• Possible to add custom methods with options (url, HTTP method, cache, …)
63
$resource
• Get the resource: myResource.get({userId: 1234})
• $resource “magic object”: Calling a $resource method returns immediately
an empty response object. That object will be filled when the response is
received.
• This object has also a $promise property which is a promise that will be
resolved when the response arrives
• So both usages are possible:
– $scope.myResources = myResource.get(…); => Simple. The view will display
returned data when it’s available.
– myResource.get(…).$promise().then([success], [error]); => More advanced.
Manage loader image, errors, …
64
$resource (2)
• It’s an AngularJs service that simplifies requesting a RESTful API.
• No $resource bugs (?)
• It supports all HTTP methods.
• It supports self-linking elements
• It uses promises, instead of $resource ‘s “magic object”.
– But there is still a “magic object” available (“$object” property) ;-)
• Possible to extends API results (extendModel and extendCollection)
• Configuration (global and/or by service)
– setBaseUrl
– setDefaultHttpFields
– Response/request interceptors
– etc
65
RestAngular
• Web API exemple: http://myapi/accounts/45/buildings/1234
• Using RestAngular :
– Restangular.all('accounts') => “/accounts” route – No request sent
– Restangular.all('accounts').getList() => Request the API and returns a promise for the list.
– Restangular.one('accounts', 1234) => “/accounts/1234” route – No request sent
– Restangular.one('accounts', 1234).get() => Request the API and returns a promise for the
element.
– Restangular.one('accounts', 123).one('buildings', 456).get() => Chaining methods to get that
element (“/accounts/123/buildings/456”)
• It’s also possible to call a specific URL: Restangular.allUrl('searches', 'http://google.com/‘);
66
RestAngular (2)
• same template for all js file:
(function (undefined) {
'use strict';
…
})();
include in the great SideWaffle visual studio extension : http://sidewaffle.com/
Here this the JavaScript IIFE template.
• use JS Hint with Web Essentials for visual studio
(http://vswebessentials.com/features/javascript) and customize the settings
with the json provided at the end of this document.
 check your messages in error list !
67
Betclic Best practices - Javascript
• never create variable to get the module :
avoid :
var app = angular.module("sportWebApp");
app.controller('watheverCtrl')....
recommended :
angular.module("sportWebApp").controller('watheverCtrl')....
• directive convention :
use replace true
use E for templating
use A for behavior
never use Class or Comment
always use data-xxx to pass param to an isolated scope
 W3C  ! 68
Betclic Best practices - AngularJs coding
• use $inject , to remove the [] inline
• use named functions instead of passing anonymous function to get cleaner
code, better readability, easier debug and reduces the nested callback code
.controller('myCtrl',['$scope','toto',function ($scope,toto){
....
}])

.controller('myCtrl',myCtrl);
myCtrl.$inject=['$scope','toto'];
function myCtrl($scope,toto){
....
} 69
Betclic Best practices - AngularJs coding
• add comments for each js file , with this template
/**
* @desc [un casing name] that [display/filter/use for] [functionality detail]
* @file [file name (no path)]
* @example [example of using in html for directive/filter or in js for service]
*/
70
Betclic Best practices - AngularJs coding
• naming convention :
controller :
file name : xxxCtrl.js
object name : xxxCtrl
service :
file name : xxxSvc.js
object name : xxxSvc
directive :
file name : [domaine/page prefix]xxxCtrl.js
object name : bcsp[domaine/page prefix]xxxx
(bcsp stand for betclic sport)
example : evtCompetitionHeaderDir.js / bcspEvtCompetitionHeader
using in the html example :
<bcsp-evt-competition-header></bcsp-evt-competition-header> 71
Betclic Best practices - Naming , solution organization
• 'shared' folder at the root of the 'app' : all the common directives, service,
filters etc ...
[domaine/page prefix] is here the full name, ex : market/marketDir.js
• Mirror the app to an app folder in the unit test project
 a xxx.js file in the web app should have a xxxTest.js file in the Test project.
• Single Responsibility , Rule of 1: Define 1 component per file.
• Directives, Limit 1 Per File: Create one directive per file. Name the file for
the directive.
72
Betclic Best practices - Naming , solution organization
73
Conclusion
• http://blog.xebia.com/2013/09/01/differences-between-providers-in-
angularjs/
• http://www.synbioz.com/blog/la_creation_de_service_avec_angularjs
• http://www.frangular.com/2012/12/differentes-facons-de-creer-un-service-
angularjs.html
• http://lostechies.com/gabrielschenker/2014/02/26/angular-jspart-13-
services/
• http://stackoverflow.com/questions/15666048/angular-js-service-vs-
provider-vs-factory
• http://sametmax.com/service-factory-et-provider-dans-angularjs/
• http://www.johnpapa.net/angular-style-guide/
75
Reference Services
• http://mgonto.github.io/restangular-talk-with-image-right/#28
• http://www.ng-newsletter.com/posts/restangular.html
• http://ath3nd.wordpress.com/2013/08/05/15/
• https://github.com/mgonto/restangular
• http://ath3nd.wordpress.com/2013/08/05/15/
76
Restangular
• Settings recommended :
77
.jshintrc
Find out more
• On https://techblog.betclicgroup.com/
We want our Sports betting, Poker, Horse
racing and Casino & Games brands to be easy
to use for every gamer around the world.
Code with us to make that happen.
Look at all the challenges we offer HERE
We are hiring !
Check our Employer Page
Follow us on LinkedIn
About Us
• Betclic Everest Group, one of the world leaders in online
gaming, has a unique portfolio comprising various
complementary international brands: Betclic, Everest,
Bet-at-home.com, Expekt, Monte-Carlo Casino…
• Through our brands, Betclic Everest Group places
expertise, technological know-how and security at the
heart of our strategy to deliver an on-line gaming offer
attuned to the passion of our players. We want our
brands to be easy to use for every gamer around the
world. We’re building our company to make that happen.
• Active in 100 countries with more than 12 million
customers worldwide, the Group is committed to
promoting secure and responsible gaming and is a
member of several international professional associations
including the EGBA (European Gaming and Betting
Association) and the ESSA (European Sports Security
Association).

More Related Content

What's hot

AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Nir Kaufman
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreAri Lerner
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSArmin Vieweg
 
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
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSparkhound Inc.
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXJWORKS powered by Ordina
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJSInfragistics
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0Nagaraju Sangam
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSDavid Parsons
 

What's hot (20)

Angular js
Angular jsAngular js
Angular js
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library 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
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 

Viewers also liked

The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media QueriesRuss Weakley
 
Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworksNicole Ryan
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBrad Frost
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesLitmus
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5Kenichi Kanai
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tipsChris Love
 

Viewers also liked (9)

AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworks
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web Design
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best Practices
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
 

Similar to AngularJS Best Practices

Angular presentation
Angular presentationAngular presentation
Angular presentationMatus Szabo
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular jsMindfire Solutions
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in AngularAlexe Bogdan
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSSumanth krishna
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
Angular Presentation
Angular PresentationAngular Presentation
Angular PresentationAdam Moore
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 

Similar to AngularJS Best Practices (20)

Angular 9
Angular 9 Angular 9
Angular 9
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
 
Angular js
Angular jsAngular js
Angular js
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJS
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Angular js
Angular jsAngular js
Angular js
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
 
17612235.ppt
17612235.ppt17612235.ppt
17612235.ppt
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
AngularJS
AngularJSAngularJS
AngularJS
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 

More from Betclic Everest Group Tech Team

Mini-training: Personalization & Recommendation Demystified
Mini-training: Personalization & Recommendation DemystifiedMini-training: Personalization & Recommendation Demystified
Mini-training: Personalization & Recommendation DemystifiedBetclic Everest Group Tech Team
 

More from Betclic Everest Group Tech Team (20)

Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
Mini training - Introduction to Microsoft Azure Storage
Mini training - Introduction to Microsoft Azure StorageMini training - Introduction to Microsoft Azure Storage
Mini training - Introduction to Microsoft Azure Storage
 
Akka.Net
Akka.NetAkka.Net
Akka.Net
 
Mini training- Scenario Driven Design
Mini training- Scenario Driven DesignMini training- Scenario Driven Design
Mini training- Scenario Driven Design
 
Email Management in Outlook
Email Management in OutlookEmail Management in Outlook
Email Management in Outlook
 
Mini-Training: SSO with Windows Identity Foundation
Mini-Training: SSO with Windows Identity FoundationMini-Training: SSO with Windows Identity Foundation
Mini-Training: SSO with Windows Identity Foundation
 
Training - What is Performance ?
Training  - What is Performance ?Training  - What is Performance ?
Training - What is Performance ?
 
Mini-Training: Docker
Mini-Training: DockerMini-Training: Docker
Mini-Training: Docker
 
Mini Training Flyway
Mini Training FlywayMini Training Flyway
Mini Training Flyway
 
Mini-Training: NDepend
Mini-Training: NDependMini-Training: NDepend
Mini-Training: NDepend
 
Management 3.0 Workout
Management 3.0 WorkoutManagement 3.0 Workout
Management 3.0 Workout
 
Lean for Business
Lean for BusinessLean for Business
Lean for Business
 
Short-Training asp.net vNext
Short-Training asp.net vNextShort-Training asp.net vNext
Short-Training asp.net vNext
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Mini-Training: Mobile UX Trends
Mini-Training: Mobile UX TrendsMini-Training: Mobile UX Trends
Mini-Training: Mobile UX Trends
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
Mini-training: Personalization & Recommendation Demystified
Mini-training: Personalization & Recommendation DemystifiedMini-training: Personalization & Recommendation Demystified
Mini-training: Personalization & Recommendation Demystified
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
Mini-Training: Roslyn
Mini-Training: RoslynMini-Training: Roslyn
Mini-Training: Roslyn
 

Recently uploaded

定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleanscorenetworkseo
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 

Recently uploaded (20)

定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleans
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 

AngularJS Best Practices

  • 2. • File Organization • Namespacing and File naming • Understanding Modules • Organizing modules • Minification • Definitions and roles • Controllers • Services • Directives • Scope • Communicating between components • Avoiding FOUC • Thinking Declaratively • Directives as a DSL • Breaking Down A Page into Components • $resource • Restangular • Betclic best practices • Conclusion Agenda Note: all screenshots are copyright from their respective owners.
  • 3. • Basic Only for a small POC app 3 File Organization
  • 4. • By feature 4 File Organization
  • 5. • By feature then type If more than 15 files , split by type Don’t forget that the file organization doesn’t reflect how code is delivered 5 File Organization
  • 6. • Miror app file organization for unit test • Keep same file name + ‘Test’ 6 File Organization
  • 7. • Why naming ? – Object type reading – Avoid collisions (silent with Ajs!) 7 Namespacing and File naming
  • 8. • NameSpacing solution (2 or 3 letters pre-fix) : 8 Namespacing and File naming
  • 9. • Controllers : ScheduleCtrl • Services : ScheduleSvc • Filters : RatingFilter • Directives : small-schedule • Partials : – if my controller is ScheduleCtrl  ScheduleCtrl.html – If my directives is small-schedule  small-schedule.html 9 Namespacing and File naming
  • 11. • Modules have nothing to do with object naming (so far…) • The Injector has the list of all the objects in our application • Only one injector exists in each Angular application 11 Understanding Modules Modules
  • 12. • One Module + it's the simplest option by far you don't have to worry about how your module organization reflects the organization of your files and folders, and you still only need to deliver the code you want running in the browser. - if you have code that you are sharing amongst several applications, then they all need to have the same module name. - delivering code as a third party or publishing it to the open source community is not really a possibility. 12 Organizing modules
  • 13. • Two Modules One for code custom to the current application, and one for any shared code. + simplicity - increased complexity, and some rigidity when sharing or publishing code. This strategy works best if you will be building multiple applications that may share some code, or if you intend to publish a portion of your code to third parties, or you plan to open source it, say a library of widgets. 13 Organizing modules
  • 14. • MainModule with several sub-modules The MainModule may or may not have any actual objects in it, it might just be a collection of sub-modules. + you have tons of organization for your code Modules become an extra way to organize and deliver just the parts of your application that you want to deliver. - increased complexity of managing those different modules. - build system will have to be more complex as well 14 Organizing modules
  • 15. var servicesA = angular.module('servicesA', []); var servicesB = angular.module('servicesB', []); var serviceApp = angular.module('serviceApp', ['servicesA‘, 'servicesB']); 15 MainModule with several sub-modules Example
  • 16. • removing all unnecessary whitespace • rename variables and parameters to short names. Problem : Angular uses reflection to look at parameter names of certain functions like controllers and services, so that its dependency injector can provide the correct dependency angular.module('app').controller('Controller1',function($scope, mySvc) { $scope.val = mySvc.val; }) .NET bundling  angular.module('app').controller('Controller1',function(a, b) { a.val = b.val; }) 16 Minification
  • 17. • Node solution : ng-min • Our solution : classic .net bundling on fly Constraints , we need to write that way: angular.module('app').controller('Controller1', ['$scope','mySvc', function($scope, mySvc) { $scope.val = mySvc.val;}]) I 17 Minification
  • 18. • Controllers – setup the scope – view interaction • Services – handle non-view logic – communicate with the server – hold data & state (not the only one) – DOM manipulation (code smell ;)) – Business • Directives – Manipulate DOM – Receive View Events 18 Definitions and roles • Views – Display the application – Declare bindings & directives
  • 19. • coordinate View and Model Nothing else, the ctrl shouldn’t knwon the business logic or the model structure angular.module('app').controller('scheduleCtrl',function($scope, schedule) { $scope.schedule = schedule; $scope.register = function(newClass) { $scope.schedule.register(newClass); } }); • Limited # of collaborators  split the ctrl in smaller ones  Facade pattern • Testable 19 Controllers – Design guidelines
  • 20. A service is treated as a singleton, that is there is only one instance of a specific service available during the whole lifetime of the Angular application. This is different from e.g. a controller of which many instances can be created. app.service(‘registration’, function() { return { title: ‘Service from Service’ } }); But in Angular there are actually sevral ways to create a service 20 Services - creation
  • 21. app.value(‘myValService’, ‘someValue’); What the value function does is create a service that is exactly what you passed into the value function. We can define any string, number, date-time, array or object as a value. We can even register a function as a value This could be things like the full name of the user, it’s role and so on. Typically we would load this data after the user has successfully logged into the system and keep this data around as long as the user remains logged in. Dependancy Injection is not possible. 21 Services –value
  • 22. The constant function is essentially the same as the value function, except it's available during the app configuration phase. app.constant(‘myValService’, ‘someValue’); The difference between a value and a constant service is that the former can only be injected (and thus be used) in a service or a controller while the latter can also be injected into a module configuration function.. Dependancy Injection is not possible. 22 Services – constant
  • 23. Example app.constant(‘myValService’, ‘someValue’);  var app = angular.module('app', []); app.config(function ($provide) { $provide.constant('movieTitle', 'The Matrix'); }); app.controller('ctrl', function (movieTitle) { expect(movieTitle).toEqual('The Matrix'); }); 23 Services – constant
  • 24. The purpose of the factory function is to generate the single object, or function, that represents the service to the rest of the application. app.factory('profile', function() { return { "name": "Anonymous", "Id": null, "login": function(){…}, "logout": function(){…} } }); So the factory function is simply just the normal way to create a service. Notice that the factory function can ask for other dependencies. 24 Services - factory
  • 25. The service function is a lot like the factory function with one difference. The service function will take the function you give it and call new on it. Then it will cache the result of that function and give you the result every time you ask for that service. monApp.service('profile', function() { this.name = "Anonymous"; this.id = null; this.login = function(){…} this.logout = function(){…} }); « return » isn’t required. Generally factory is all you need. No question regarding the “this” ! 25 Services - service
  • 26. This function is ultimately what all those other functions use under the covers. This allows you to create a service from a much lower level. What you have to do is give the provider function another function whose return value must have a $get function. A provider is actually a configurable factory. The provider accepts an object or a constructor. The benefit here is that using provider, you have the option to make your service configurable and configure it before it is created. Offical Reco : You should use the Provider recipe only when you want to expose an API for application-wide configuration that must be made before the application starts. This is usually interesting only for reusable services whose behavior might need to vary slightly between applications. 26 Services - provider
  • 27. angular.module('app').controller('scheduleCtrl',function($scope, registration) { $scope.title = registration.title; }); app.config(function($provide) { $provide.provider('registration', function() { var type; return { setType: function(value) { type = value; }, $get: function() { return { title: 'Service from Provider ' + type } } } })}) app.config(function(registrationProvider) { registrationProvider.setType('Angular'); }) 27 Services - provider
  • 28. A decorator can modify or encapsulate other providers. There is one exception and that a constant cannot be decorated 28 Services - Decorator var app = angular.module('app', []); app.value('movieTitle', 'The Matrix'); app.config(function ($provide) { $provide.decorator('movieTitle', function ($delegate) { return $delegate + ' - starring Keanu Reeves'; }); }); app.controller('myController', function (movieTitle) { expect(movieTitle).toEqual('The Matrix - starring Keanu Reeves'); });
  • 29. Filters are really just a service with a specific kind of name. 29 Services – filters as services app.factory("ratingsFilter", function() { return function(input) { var rating = parseInt(input); var result = ""; for(var i=0; i < rating; i++) { result += "*"; } return result; } }); app.filter("ratings", function() { return function(input) { var rating = parseInt(input); var result = ""; for(var i=0; i < rating; i++) { result += "*"; } return result; } });
  • 30. • SRP : single responsability ! • Cohesive : having all the functionality of an object relate to the primary purpose of the object • Loosely Coupled : A good service should be loosely coupled to any dependencies that it has. • Good interface : Any situation where you call multiple methods to do a single job is less effective. • Testable 30 Services – Design Guidelines
  • 31. function Course(title, instructorIds, id) { this.title = title; this.instructorIds = instructorIds; this.id = id; } Course.prototype.displayName = function() { // code } … app.value('courseFactory', { createCourse: function(title, credits, department, instructors) { var instructorIds = []; for(var i=0; i < instructors.length; i++) { instructorIds.push(instructors[i].id); } return new Course(title, instructorIds, -1); } }) 31 Services - Specific Types - Factories
  • 32. app.value('schedule', { classes: [], addClass: function(newClass) { for(var i=0; i < this.classes.length; i++) { if(this.classes[i] === newClass) { return; } } this.classes.push(newClass); }, dropClass: function(classToDrop) { for(var i=0; i < this.classes.length; i++) { if(this.classes[i] === classToDrop) { this.classes.splice(i, 1); } } } }) 32 Services - Specific Types - Stateful Singletons
  • 33. app.value('grades', []); app.value('calculateGPA', function(grades) { // implementation return "4.0"; }) app.controller('userCtrl',function($scope, grades, calculateGPA) { $scope.GPA = calculateGPA(grades); }); 33 Services - Specific Types - Functions
  • 34. • Services Syntax: module.service( 'serviceName', function ); Result: When declaring serviceName as an injectable argument you will be provided with an instance of the function. In other words new FunctionYouPassedToService(). • Factories Syntax: module.factory( 'factoryName', function ); Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory. • Providers Syntax: module.provider( 'providerName', function ); Result: When declaring providerName as an injectable argument you will be provided with ProviderFunction().$get(). The constructor function is instantiated before the $get method is called - ProviderFunction is the function reference passed to module.provider. 34 Services - Summary
  • 35. • Purposes of directives piece of visible display that may or not be reusable, but whose functionality is encapsulated and an interface provided so that the widget can easily represent a piece of display and functionality of your app • Classic Error : In The javascript : myDirective (CamelCase) In the view : my-directive (snake case)  First thing to check in case of error : check the names  • Naming Convention: prefix : bc/bcsp ? A directive should be unique because Ajs doesn’t override, but stack. 35 Directives
  • 36. JS: app.directive(‘bcHelloWorld', function() { return { restrict: 'E', replace: 'true', template: '<h3>Hello World!!</h3>' }; }); Html: <bc-hello-world/> 36 Directives
  • 37. • restrict: 'E' => Element : <date-picker></date-picker> • restrict: ‘A' => Attributes: <input type="text" date-picker/> • restrict: 'C' => class : <input type="text" class="date-picker"/> • restrict: 'M' => comment : <!--directive:date-picker--> Combine possible, for example : restrict: 'AE‘ Html5 compliant : <input type="text" data-date-picker/> 37 Directives - restrict
  • 38. • Template : inline • TemplateUrl : path to html file 38 Directives – template / templateUrl
  • 39. True : <h3>Hello World!!</h3> False: <hello-world><h3>Hello World!!</h3></hello-world> 39 Directives – replace
  • 40. app.directive('helloWorld', function() { return { restrict: 'AE', replace: true, template: '<p style="background-color:{{color}}">Hello World', link: function(scope, elem, attrs) { elem.bind('click', function() { elem.css('background-color', 'white'); scope.$apply(function() { scope.color = "white"; }); }); elem.bind('mouseover', function() { elem.css('cursor', 'pointer'); }); } }; 40 Directives – Link
  • 41. It takes three arguments: • scope – The scope passed to the directive. In this case it’s the same as the parent controller scope. • elem – The jQLite (a subset of jQuery) wrapped element on which the directive is applied. If you have included jQuery in the HTML before AngularJS is included, this becomes jQuery wrapped instead of jQLite. As the element is already wrapped with jQuery/jQLite, there is no need to again wrap it inside $() for DOM manipulations. • attrs – An object representing normalized attributes attached to the element on which the directive is applied. For example, you can attach attributes in HTML like: <hello-world some-attribute></hello-world> and access it in the link function as attrs.someAttribute. 41 Directives – Link
  • 42. return { restrict:'E', require: 'nameOfSiblingController' } Ability to require in a controller from another directive, Return null if the required isn’t here. Require on parent : return { restrict:'E', require: '^nameOfParentController' } 42 Directives – Require
  • 43. 2 solutions : • put the functionality into the link function of the directive • create a controller and put that functionality into the controller (can be no inline to reuse it) controller: function($scope) { $scope.viewClassDetails = function(classToView) { // do something console.log('viewing details for ' + classToView.name); } <=> link: function(scope) { scope.viewClassDetails = function(classToView) { // do something console.log('viewing details for ' + classToView.name); } } 43 Directives - Controllers vs Link
  • 44. Ask yourself “when do I want my code to run?” Before compilation? – Controller After compilation? – Link  Never condone putting DOM manipulation in an angular controller “Am I just doing template and scope things?” – goes into controller “Am I adding some coolbeans jquery library?” – goes in link http://jasonmore.net/angular-js-directives-difference-controller-link/ 44 Directives - Controllers vs Link
  • 45. there are 3 ways for a directive to interface with a containing scope: 1. share the scope 2. create an inherited scope 3. create an isolated scope 1&2 : the directive simply has access to all the objects in the containing scope Stop !!!! What is the scope ?? 45 Directives - interfaces
  • 46. In Angular, the scope is the magic. All binding happens through a scope, all interaction happens through a scope.  very important to understand Help to debug : chrome extension « AngularJS Batarang » 1. on top i have the root scope / ng-app correspond to the root scope 2. all scopes belong to exactly 1 Element 3. 1 scope <=> 1 ng-controller 46 Scope - Dealing with scope
  • 47. 47 Scope - Dealing with scope
  • 48. • By default 48 Scope - Sharing scope
  • 49. app.directive('scInstructorCount', function() { return { scope: true, link: function(scope) { scope.instructorList.push({id:4, name: 'Professor Lockhart'}); scope.CurrentInstructorId = 22; } } }); Example : only the directive see the CurrentInstructorId 49 Scope - inherited scope
  • 50. WARING EASY BUG !! how do you correctly bind an ngModel to a parent scope item => make sure there is a dot in the binding 50 Scope - inherited scope
  • 51. app.directive('scInstructorCount', function() { return { restrict: 'A', replace: true, templateUrl: 'scInstructorCount.html', scope: { instructorList: '=', title: '=' }, link: function(scope) { scope.title = "My New Title"; } } }); <div sc-instructor-count instructor-list="instructorList" title="title" sc-new- instructor></div> 51 Scope - Isolating scope WARNING snake-case / camel- case Two way binding !
  • 52. + : easy - : hidden dependencies - : put things in the parent useless for him, here only for the childs 52 Communicating between components Communicating with Inherited Scopes
  • 53. • Use global bus: $rootScope.$broadcast("course:registered", course);  $scope.$on('course:registered', function(event, course) { $scope.notify('You have registered for ' + course.name); }) + : logic, responsability inside the ctrl - : add $rootscope to every listeners, a listener could cancel the event - : warning to the string name of the event 53 Communicating between components Communicating with Events
  • 54. A service is a singleton so it’s the same for every body. + : business logic is in the right place - : more set-up work - : difficult to draw the line between display logic and business logic 54 Communicating between components Communicating with Services
  • 55. I see dead brackets !!!! It happen more for classic website, not for SPA. Solution 1: ngCloak Need to add style in css : [ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; } We add the directive ngCloak on the place we want to hide before the binding ( not too high, to not display too much white space) 55 Avoiding FOUC Flash of Unstyled Content
  • 56. Solution 2: ngBind <h1>{{name}}</h1>  <h1 ng-bind="name">&nbsp;</h1> But we still have a problem with ng-hide, which hide nothing until the binding, 56 Avoiding FOUC Flash of Unstyled Content
  • 57. Solution 3: Waiting image <img src="spinner.gif" ng-hide="ready" style="width:400px" /> <div ng-cloak ng-show="ready" class="jumbotron">..</div> The « ready » variable is set to true when the data are loaded, 57 Avoiding FOUC Flash of Unstyled Content
  • 58. old way : write Html, write Jquery to manipulate the DOM Angular Way: • Put declarative View Logic in the View • Don't put imperative logic in the view  imperative code belongs in the controller, declarative code belongs in the view Thinking about how to do something with the view might lead us down the wrong road Thinking declaratively,what we want to do is represent our state in our controller and then get the view to manipulate itself based on that state. The controler should not take control of the view but the view should listen to the scope !  clean code. 58 Thinking Declaratively
  • 59. create custom HTML through directives  not only powerful, it is truly paradigm changing when it comes to web development your HTML turn a low-level description of the layout of a web page into a domain-specific language that describes the functionality of your application  Primary type to object !  HTML not only technic, it has to be readable ! 59 Directives as a DSL
  • 60. • Inline controllers (only js) • Controllers and ngInclude (html) • Directives (js + html) 60 Breaking Down A Page into Components
  • 61. • Manage deferred tasks (e.g. asynchronous tasks) • Methods – then(successCallback, errorCallback, notifyCallback): callback for successfully resolved promise, callback for error (optional), and notify (optionnal, see « deferred ») – catch(errorCallback): callback for error – finally(callback): callback for either success or error but with no data modification (?) • Promises can be chained. 61 Promises
  • 62. • Creates and manipulates a promise • Methods: – resolve(value): ends the promise (success) with the given value – reject(reason): same but with an error – notify(value): updates promise without ending it • Promise : property that gives the associated promise object • $q (injectable) – create a deferred object: $q.defer() – Method “all”: Use to combine multiple promises into a single one (resolved when all promises are resolved; rejected when any promise is rejected), 62 Deferred
  • 63. • Factory AngularJS to interact with RESTful APIs • Module: ‘ngResource’ • Basic usage: • Returns object with defaults methods: { 'get': {method:'GET'}, 'save': {method:'POST'}, 'query': {method:'GET', isArray:true}, 'remove': {method:'DELETE'}, 'delete': {method:'DELETE'} } • Possible to add custom methods with options (url, HTTP method, cache, …) 63 $resource
  • 64. • Get the resource: myResource.get({userId: 1234}) • $resource “magic object”: Calling a $resource method returns immediately an empty response object. That object will be filled when the response is received. • This object has also a $promise property which is a promise that will be resolved when the response arrives • So both usages are possible: – $scope.myResources = myResource.get(…); => Simple. The view will display returned data when it’s available. – myResource.get(…).$promise().then([success], [error]); => More advanced. Manage loader image, errors, … 64 $resource (2)
  • 65. • It’s an AngularJs service that simplifies requesting a RESTful API. • No $resource bugs (?) • It supports all HTTP methods. • It supports self-linking elements • It uses promises, instead of $resource ‘s “magic object”. – But there is still a “magic object” available (“$object” property) ;-) • Possible to extends API results (extendModel and extendCollection) • Configuration (global and/or by service) – setBaseUrl – setDefaultHttpFields – Response/request interceptors – etc 65 RestAngular
  • 66. • Web API exemple: http://myapi/accounts/45/buildings/1234 • Using RestAngular : – Restangular.all('accounts') => “/accounts” route – No request sent – Restangular.all('accounts').getList() => Request the API and returns a promise for the list. – Restangular.one('accounts', 1234) => “/accounts/1234” route – No request sent – Restangular.one('accounts', 1234).get() => Request the API and returns a promise for the element. – Restangular.one('accounts', 123).one('buildings', 456).get() => Chaining methods to get that element (“/accounts/123/buildings/456”) • It’s also possible to call a specific URL: Restangular.allUrl('searches', 'http://google.com/‘); 66 RestAngular (2)
  • 67. • same template for all js file: (function (undefined) { 'use strict'; … })(); include in the great SideWaffle visual studio extension : http://sidewaffle.com/ Here this the JavaScript IIFE template. • use JS Hint with Web Essentials for visual studio (http://vswebessentials.com/features/javascript) and customize the settings with the json provided at the end of this document.  check your messages in error list ! 67 Betclic Best practices - Javascript
  • 68. • never create variable to get the module : avoid : var app = angular.module("sportWebApp"); app.controller('watheverCtrl').... recommended : angular.module("sportWebApp").controller('watheverCtrl').... • directive convention : use replace true use E for templating use A for behavior never use Class or Comment always use data-xxx to pass param to an isolated scope  W3C  ! 68 Betclic Best practices - AngularJs coding
  • 69. • use $inject , to remove the [] inline • use named functions instead of passing anonymous function to get cleaner code, better readability, easier debug and reduces the nested callback code .controller('myCtrl',['$scope','toto',function ($scope,toto){ .... }])  .controller('myCtrl',myCtrl); myCtrl.$inject=['$scope','toto']; function myCtrl($scope,toto){ .... } 69 Betclic Best practices - AngularJs coding
  • 70. • add comments for each js file , with this template /** * @desc [un casing name] that [display/filter/use for] [functionality detail] * @file [file name (no path)] * @example [example of using in html for directive/filter or in js for service] */ 70 Betclic Best practices - AngularJs coding
  • 71. • naming convention : controller : file name : xxxCtrl.js object name : xxxCtrl service : file name : xxxSvc.js object name : xxxSvc directive : file name : [domaine/page prefix]xxxCtrl.js object name : bcsp[domaine/page prefix]xxxx (bcsp stand for betclic sport) example : evtCompetitionHeaderDir.js / bcspEvtCompetitionHeader using in the html example : <bcsp-evt-competition-header></bcsp-evt-competition-header> 71 Betclic Best practices - Naming , solution organization
  • 72. • 'shared' folder at the root of the 'app' : all the common directives, service, filters etc ... [domaine/page prefix] is here the full name, ex : market/marketDir.js • Mirror the app to an app folder in the unit test project  a xxx.js file in the web app should have a xxxTest.js file in the Test project. • Single Responsibility , Rule of 1: Define 1 component per file. • Directives, Limit 1 Per File: Create one directive per file. Name the file for the directive. 72 Betclic Best practices - Naming , solution organization
  • 74.
  • 75. • http://blog.xebia.com/2013/09/01/differences-between-providers-in- angularjs/ • http://www.synbioz.com/blog/la_creation_de_service_avec_angularjs • http://www.frangular.com/2012/12/differentes-facons-de-creer-un-service- angularjs.html • http://lostechies.com/gabrielschenker/2014/02/26/angular-jspart-13- services/ • http://stackoverflow.com/questions/15666048/angular-js-service-vs- provider-vs-factory • http://sametmax.com/service-factory-et-provider-dans-angularjs/ • http://www.johnpapa.net/angular-style-guide/ 75 Reference Services
  • 76. • http://mgonto.github.io/restangular-talk-with-image-right/#28 • http://www.ng-newsletter.com/posts/restangular.html • http://ath3nd.wordpress.com/2013/08/05/15/ • https://github.com/mgonto/restangular • http://ath3nd.wordpress.com/2013/08/05/15/ 76 Restangular
  • 77. • Settings recommended : 77 .jshintrc
  • 78. Find out more • On https://techblog.betclicgroup.com/
  • 79. We want our Sports betting, Poker, Horse racing and Casino & Games brands to be easy to use for every gamer around the world. Code with us to make that happen. Look at all the challenges we offer HERE We are hiring ! Check our Employer Page Follow us on LinkedIn
  • 80. About Us • Betclic Everest Group, one of the world leaders in online gaming, has a unique portfolio comprising various complementary international brands: Betclic, Everest, Bet-at-home.com, Expekt, Monte-Carlo Casino… • Through our brands, Betclic Everest Group places expertise, technological know-how and security at the heart of our strategy to deliver an on-line gaming offer attuned to the passion of our players. We want our brands to be easy to use for every gamer around the world. We’re building our company to make that happen. • Active in 100 countries with more than 12 million customers worldwide, the Group is committed to promoting secure and responsible gaming and is a member of several international professional associations including the EGBA (European Gaming and Betting Association) and the ESSA (European Sports Security Association).