SlideShare uma empresa Scribd logo
1 de 41
AngularJS 101
Everything you need to know to get started
+stephane.begaudeau @sbegaudeau stephanebegaudeau.tumblr.com
Why Angular?
to create properly architectured and
maintainable web applications
Expressions
To create the views of your applications, you can use expressions within your HTML
● Javascript like code
● Used for small operations in the HTML page
Expressions are nice for small operations, for real applications, we have something more powerful
<div>1+1 = {{1+1}}</div>
Directives
what HTML would have been, had it been
designed for building web-apps
Directives
Extends HTML to structure your application
● Declarative
● Use the data available in the scope (more on that later)
● Create the DOM of the fly
Let's have a look at an example: ngRepeat.
It iterates on a collection in the scope to create the DOM
<div>
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
</div>
</div>
Directives - ngRepeat
For each elements in the collection "users" a new <div> has been created with all its children
<div>
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
</div>
</div>
Directives - ngShow
AngularJS comes with a collection of standard directives that can be combined
ngShow let you hide elements that do not validate a given predicate
Here, the users that do not have the gender "female" have generated a hidden <div>
<div>
<div ng-repeat="user in users" ng-show="user.gender == 'female'">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
</div>
</div>
Directives - ngSwitch
AngularJS also provides you with complex directives like ngSwitch
With those directives, you can create the basic structure of your web application easily
<div>
<div ng-repeat="user in users"
ng-show="user.gender == 'female'"
ng-switch="user.house">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
Sigil:
<img src="images/targaryen.gif" ng-switch-when="Targaryen">
<img src="images/stark.gif" ng-switch-when="Stark">
<img src="images/lannister.gif" ng-switch-when="Lannister">
</div>
</div>
Directives
A final word on directives
● All the directives of the AngularJS standard library are named "ngMyAwesomeDirective"
● You can use them with "ng-my-awesome-directive"
● Some directives can be used as attributes, comments, DOM elements name or even CSS classes
And of course, you can create your own directives (we will create a very basic one later)
<div>
<div ng-my-awesome-directive></div>
<ng-my-awesome-directive></ng-my-awesome-directive>
<div class="ng-my-awesome-directive"></div>
<!-- directive: ng-my-awesome-directive -->
</div>
Data Binding
connect your models and your views
Data Binding
Angular gives you the ability to define the binding between the data in your scope and your views
● Most directives that are using expressions are creating a bidirectionnal data binding for you
● You can create manually new bindings with the directive ngModel
The changes are visible in real-time in all the expressions
<div>
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
Edit Description:
<textarea rows="5" cols="50" ng-model="user.description">
</div>
</div>
Filters
change the way your expressions are displayed
Filters - uppercase
Angular comes with a collection of filters that can change the way your data are displayed
● Usage: {{expression | filter}}
You can also easily create your own filters
<div>
<div ng-repeat="user in users">
<h3>{{user.name | uppercase}}</h3>
<p>{{user.description}}</p>
Edit Description:
<textarea rows="5" cols="50" ng-model="user.description">
</div>
</div>
Partial Views
single page web applications at best
Partial Views
Everything you need to build single page applications
● Angular handles the History management
● You can easily bind your views to the routes
All you need to do is
● Creates the page that will hold the structure of the application
● Bind the page to a specific AngularJS module thanks to ngApp
● Select where the views will be included with ngView
● Writes the different views
● Binds the view and the routes
Partial Views - ngView
● When the route changes, Angular will load the partial view in the DOM thanks to ngView
● The views can be created in other HTML files
● We will see later how we can bind a view to a route
<!DOCTYPE html>
<html>
<head><title>AngularJS</title></head>
<body ng-app="AngularJSModule">
<div ng-view>Loading...</div>
<!-- vendors -->
<script src="angular.min.js"></script>
<!-- modules -->
<script src="app.js"></script>
<!-- controllers -->
<script src="users.js"></script>
</body>
</html>
<div>
<div ng-repeat="user in users">
<h3>{{user.name | uppercase}}</h3>
<p>{{user.description}}</p>
</div>
</div>
index.html
users.html
Modules
the structure of your application
Modules and ngApp
In AngularJS, applications are structured in modules
You can define a new module very easily thanks to the function "module'
You just have to declare the name of the module and an array containing the name of the
modules that you wre depending on
Inside of a module, you can create:
● controllers
● services
● filters
● directives
var angularJSModule = angular.module('AngularJSModule', []);
Modules and ngApp
Use ngApp, in order to tell Angular that a part of your application will be manage by a module
var angularJSModule = angular.module('AngularJSModule', []);
<!DOCTYPE html>
<html>
<head><title>AngularJS</title></head>
<body ng-app="AngularJSModule">
<div ng-view>Loading...</div>
<!-- vendors -->
<script src="angular.min.js"></script>
<!-- modules -->
<script src="app.js"></script>
<!-- controllers -->
<script src="users.js"></script>
</body>
</html>
index.html
app.js
Dependency Injection
building a testable and maintainable application
Dependency Injection
In Angular, most of the operation of the framework are using dependency injection (DI)
For example, in order to configure the routes of your module, you will have to inject the service
$routeProvider in your configuration function.
All the components that you will create will specify their dependencies thanks to DI
This way, you will have a collection of small specialized components that can be easily tested
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.config(function ($routeProvider) {
// do something
});
Dependency Injection
The basic way of doing dependency injection in Angular uses the name of the parameters of the
function
This solution will not work with the minification of the code
Each time you can use dependency injection in Angular, you can use this way instead
The string '$routeProvider' would not change with the minification of the code
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.config(function ($routeProvider) {});
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.config(['$routeProvider', function ($routeProvider) {}]);
Configure The Module
binding routes, views and controllers
Configure the module
In order to create the routes of your application, you will use the $routeProvider
If the end user visit the URL "http://www.ourdomain.com/#/users", the view "views/users.html"
will be injected in the page, otherwise the view "views/404.html" will loaded.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/users', {
templateUrl: 'views/users.html',
controller: 'UsersCtrl'
});
$routeProvider.otherwise({
templateUrl: 'views/404.html'
});
}]);
Controllers
data provider for our views
Controllers
In Angular, the controller is used to provide data for the view
In order to provide the data to the view, the controller can be injected with the scope of the view
In the module, we have binded the view, the route and the controller, so the controller can receive
the scope of the view when the route is modified
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) {
// do something
}]);
<div>
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
</div>
</div>
Controllers
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) {
$scope.users = [
{
name: 'Tyrion Lannister',
description: 'Youngest son of Loard Tywin',
gender: 'male',
house: 'Lannister',
}
];
}]);
<div>
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<p>{{user.description}}</p>
Edit Description:
<textarea rows="5" cols="50" ng-model="user.description">
</div>
</div>
controller
view
result
Scope
the backbone of the views
Scope
The scope is used to link the controllers and the views to which they are binded.
A controller can add data and function in its scope and then they will be accessible in the view.
In our case, we have used in the view a variable named “users" which was created in the scope by
the controller “UsersCtrl".
A scope can have child scopes which can see the content of the parent scopes.
Each directive can create and manage its own scope.
The scope also comes with additional operations that can be quite useful to build your application
Scope - $watch
AngularJS provides the necessary tool to observe the changes on the data of the scope from the
controller.
With the operation "$watch", a controller can add a listener on an expression of the scope.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) {
$scope.users = [];
$scope.$watch('users', function (newValue, oldValue) {
console.log('The value of "users" has changed');
}, true);
}]);
Scope - $broadcast and $on
AngularJS also gives you access to a system of events and listeners on the scope.
You can use the operation "$broadcast" in order to fire an event on a specific scope, then the
event will be transmitted to the selected scope and all its children. With $on, you can receive the
event.
If you want to send an event to the whole application, you can use the root scope by injected the
service $rootScope.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) {
$scope.$on('AngularJSModule.Event', function () {
console.log('An event "AngularJSModule.Event" has been fired!');
});
$scope.$broadcast('AngularJSModule.Event');
}]);
Services
utility components of your application
Services
Controllers contains the data of the application that should be available to the view.
If you have some code that you want to re-use or that you want to separate from a controller, use
a service and inject it thanks to dependency injection.
Services can be injected into other services, filters, controllers or directives to build more complex
components.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.factory('UsersServer', [function () {
return {};
}]);
Services - public API
By using the function "factory", you can create your service and return it manually
You can then define the public API of your service and the private functions and variables
There are other ways to create your services but we won't see them here.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.factory('UsersServer', [function () {
var privateFunction = function () {};
var usersServer = {};
usersServer.publicFunction = function () {
privateFunction();
};
return usersServer;
}]);
Directives
today's HTML components
Directives
Directives are insanely powerful in Angular but it is a bit complex to create an advanced directive.
I won't explain here all the options available to create a directive, but here is a simple example.
var angularJSModule = angular.module('AngularJSModule', []);
angularJSModule.directive('whereIsThePower, [function () {
return {
template: '<p>Power resides where men believe it resides. No more and no less</p>',
replace: true
};
}]);
<div where-is-the-power></div>
One more thing
You should never ever ever manipulate the
DOM from a controller!
respect the separation of concerns, the data in the controller, the behavior in the directives
it's easier to test and easier to maintain
Wrapping things up
As you have seen it during this presentation, Angular is a MVC framework with a strong opinion on
how things should be done. It helps you build an application
● testable with dependency injection
● maintainable with small specialized components
● with reusable components
● well architectured (data in controllers, behavior in the directives, utility stuff in services)
Frameworks, libraries and tools
If you want to build an Angular application, you should have a look at those tools too
● Batarang - chrome extension to debug Angular applications
● Bower - dependency management tooling for front end applications by Twitter
● Grunt - tasks management (minification, autoreload, SASS or CoffeeScript compilation)
● Yeoman - generate preconfigured kickass web applications
● Karma - Angular tests runner
● Angular-ui - collection of Angular directives (datepicker, Google Maps, Bootstrap)
● Restangular - improved Angular services for REST communication
Thanks!
For more information and regular news about
AngularJS, follow me on Twitter or Google+

Mais conteúdo relacionado

Mais procurados

Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & AnswersRatnala Charan kumar
 
An Introduction to Vuejs
An Introduction to VuejsAn Introduction to Vuejs
An Introduction to VuejsPaddy Lock
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesWebStackAcademy
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - IntroductionWebStackAcademy
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsHolly Schinsky
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 

Mais procurados (20)

VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
.Net Core
.Net Core.Net Core
.Net Core
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & Answers
 
An Introduction to Vuejs
An Introduction to VuejsAn Introduction to Vuejs
An Introduction to Vuejs
 
Angular
AngularAngular
Angular
 
Asp.net web api
Asp.net web apiAsp.net web api
Asp.net web api
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 

Destaque

AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Get MEAN! Node.js and the MEAN stack
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stackNicholas McClay
 
Does my DIV look big in this?
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?glen_a_smith
 
Introduction to the MEAN stack
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stackYoann Gotthilf
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentationJohn Staveley
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applicationsSC5.io
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page ApplicationKMS Technology
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSM R Rony
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsThe MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsMongoDB
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 

Destaque (16)

Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Get MEAN! Node.js and the MEAN stack
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
 
Does my DIV look big in this?
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?
 
Introduction to the MEAN stack
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stack
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Single Page Applications
Single Page ApplicationsSingle Page Applications
Single Page Applications
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsThe MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 

Semelhante a AngularJS 101 - Everything you need to know to get started

AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosLearnimtactics
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSShyjal Raazi
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and conceptsSuresh Patidar
 
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 training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
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
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaBharat Makwana
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarAppfinz Technologies
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
 
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
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 

Semelhante a AngularJS 101 - Everything you need to know to get started (20)

Angular js
Angular jsAngular js
Angular js
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 
AngularJS
AngularJSAngularJS
AngularJS
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
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
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat Makwana
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
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
 
Angular js
Angular jsAngular js
Angular js
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
AngularJS.pptx
AngularJS.pptxAngularJS.pptx
AngularJS.pptx
 
Angular js
Angular jsAngular js
Angular js
 
Angular
AngularAngular
Angular
 

Mais de Stéphane Bégaudeau

Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Stéphane Bégaudeau
 
Modern Web Application Development Workflow - EclipseCon France 2014
Modern Web Application Development Workflow - EclipseCon France 2014Modern Web Application Development Workflow - EclipseCon France 2014
Modern Web Application Development Workflow - EclipseCon France 2014Stéphane Bégaudeau
 
Modern Web Application Development Workflow - web2day 2014
Modern Web Application Development Workflow - web2day 2014Modern Web Application Development Workflow - web2day 2014
Modern Web Application Development Workflow - web2day 2014Stéphane Bégaudeau
 
Modern Web Application Development Workflow - EclipseCon US 2014
Modern Web Application Development Workflow - EclipseCon US 2014Modern Web Application Development Workflow - EclipseCon US 2014
Modern Web Application Development Workflow - EclipseCon US 2014Stéphane Bégaudeau
 

Mais de Stéphane Bégaudeau (6)

Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
Modern Web Application Development Workflow - EclipseCon France 2014
Modern Web Application Development Workflow - EclipseCon France 2014Modern Web Application Development Workflow - EclipseCon France 2014
Modern Web Application Development Workflow - EclipseCon France 2014
 
Modern Web Application Development Workflow - web2day 2014
Modern Web Application Development Workflow - web2day 2014Modern Web Application Development Workflow - web2day 2014
Modern Web Application Development Workflow - web2day 2014
 
Modern Web Application Development Workflow - EclipseCon US 2014
Modern Web Application Development Workflow - EclipseCon US 2014Modern Web Application Development Workflow - EclipseCon US 2014
Modern Web Application Development Workflow - EclipseCon US 2014
 
Mylyn Task connector for Tuleap
Mylyn Task connector for TuleapMylyn Task connector for Tuleap
Mylyn Task connector for Tuleap
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

AngularJS 101 - Everything you need to know to get started

  • 1. AngularJS 101 Everything you need to know to get started +stephane.begaudeau @sbegaudeau stephanebegaudeau.tumblr.com
  • 2.
  • 3. Why Angular? to create properly architectured and maintainable web applications
  • 4. Expressions To create the views of your applications, you can use expressions within your HTML ● Javascript like code ● Used for small operations in the HTML page Expressions are nice for small operations, for real applications, we have something more powerful <div>1+1 = {{1+1}}</div>
  • 5. Directives what HTML would have been, had it been designed for building web-apps
  • 6. Directives Extends HTML to structure your application ● Declarative ● Use the data available in the scope (more on that later) ● Create the DOM of the fly Let's have a look at an example: ngRepeat. It iterates on a collection in the scope to create the DOM <div> <div ng-repeat="user in users"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> </div> </div>
  • 7. Directives - ngRepeat For each elements in the collection "users" a new <div> has been created with all its children <div> <div ng-repeat="user in users"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> </div> </div>
  • 8. Directives - ngShow AngularJS comes with a collection of standard directives that can be combined ngShow let you hide elements that do not validate a given predicate Here, the users that do not have the gender "female" have generated a hidden <div> <div> <div ng-repeat="user in users" ng-show="user.gender == 'female'"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> </div> </div>
  • 9. Directives - ngSwitch AngularJS also provides you with complex directives like ngSwitch With those directives, you can create the basic structure of your web application easily <div> <div ng-repeat="user in users" ng-show="user.gender == 'female'" ng-switch="user.house"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> Sigil: <img src="images/targaryen.gif" ng-switch-when="Targaryen"> <img src="images/stark.gif" ng-switch-when="Stark"> <img src="images/lannister.gif" ng-switch-when="Lannister"> </div> </div>
  • 10. Directives A final word on directives ● All the directives of the AngularJS standard library are named "ngMyAwesomeDirective" ● You can use them with "ng-my-awesome-directive" ● Some directives can be used as attributes, comments, DOM elements name or even CSS classes And of course, you can create your own directives (we will create a very basic one later) <div> <div ng-my-awesome-directive></div> <ng-my-awesome-directive></ng-my-awesome-directive> <div class="ng-my-awesome-directive"></div> <!-- directive: ng-my-awesome-directive --> </div>
  • 11. Data Binding connect your models and your views
  • 12. Data Binding Angular gives you the ability to define the binding between the data in your scope and your views ● Most directives that are using expressions are creating a bidirectionnal data binding for you ● You can create manually new bindings with the directive ngModel The changes are visible in real-time in all the expressions <div> <div ng-repeat="user in users"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> Edit Description: <textarea rows="5" cols="50" ng-model="user.description"> </div> </div>
  • 13. Filters change the way your expressions are displayed
  • 14. Filters - uppercase Angular comes with a collection of filters that can change the way your data are displayed ● Usage: {{expression | filter}} You can also easily create your own filters <div> <div ng-repeat="user in users"> <h3>{{user.name | uppercase}}</h3> <p>{{user.description}}</p> Edit Description: <textarea rows="5" cols="50" ng-model="user.description"> </div> </div>
  • 15. Partial Views single page web applications at best
  • 16. Partial Views Everything you need to build single page applications ● Angular handles the History management ● You can easily bind your views to the routes All you need to do is ● Creates the page that will hold the structure of the application ● Bind the page to a specific AngularJS module thanks to ngApp ● Select where the views will be included with ngView ● Writes the different views ● Binds the view and the routes
  • 17. Partial Views - ngView ● When the route changes, Angular will load the partial view in the DOM thanks to ngView ● The views can be created in other HTML files ● We will see later how we can bind a view to a route <!DOCTYPE html> <html> <head><title>AngularJS</title></head> <body ng-app="AngularJSModule"> <div ng-view>Loading...</div> <!-- vendors --> <script src="angular.min.js"></script> <!-- modules --> <script src="app.js"></script> <!-- controllers --> <script src="users.js"></script> </body> </html> <div> <div ng-repeat="user in users"> <h3>{{user.name | uppercase}}</h3> <p>{{user.description}}</p> </div> </div> index.html users.html
  • 18. Modules the structure of your application
  • 19. Modules and ngApp In AngularJS, applications are structured in modules You can define a new module very easily thanks to the function "module' You just have to declare the name of the module and an array containing the name of the modules that you wre depending on Inside of a module, you can create: ● controllers ● services ● filters ● directives var angularJSModule = angular.module('AngularJSModule', []);
  • 20. Modules and ngApp Use ngApp, in order to tell Angular that a part of your application will be manage by a module var angularJSModule = angular.module('AngularJSModule', []); <!DOCTYPE html> <html> <head><title>AngularJS</title></head> <body ng-app="AngularJSModule"> <div ng-view>Loading...</div> <!-- vendors --> <script src="angular.min.js"></script> <!-- modules --> <script src="app.js"></script> <!-- controllers --> <script src="users.js"></script> </body> </html> index.html app.js
  • 21. Dependency Injection building a testable and maintainable application
  • 22. Dependency Injection In Angular, most of the operation of the framework are using dependency injection (DI) For example, in order to configure the routes of your module, you will have to inject the service $routeProvider in your configuration function. All the components that you will create will specify their dependencies thanks to DI This way, you will have a collection of small specialized components that can be easily tested var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.config(function ($routeProvider) { // do something });
  • 23. Dependency Injection The basic way of doing dependency injection in Angular uses the name of the parameters of the function This solution will not work with the minification of the code Each time you can use dependency injection in Angular, you can use this way instead The string '$routeProvider' would not change with the minification of the code var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.config(function ($routeProvider) {}); var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.config(['$routeProvider', function ($routeProvider) {}]);
  • 24. Configure The Module binding routes, views and controllers
  • 25. Configure the module In order to create the routes of your application, you will use the $routeProvider If the end user visit the URL "http://www.ourdomain.com/#/users", the view "views/users.html" will be injected in the page, otherwise the view "views/404.html" will loaded. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/users', { templateUrl: 'views/users.html', controller: 'UsersCtrl' }); $routeProvider.otherwise({ templateUrl: 'views/404.html' }); }]);
  • 27. Controllers In Angular, the controller is used to provide data for the view In order to provide the data to the view, the controller can be injected with the scope of the view In the module, we have binded the view, the route and the controller, so the controller can receive the scope of the view when the route is modified var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) { // do something }]); <div> <div ng-repeat="user in users"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> </div> </div>
  • 28. Controllers var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) { $scope.users = [ { name: 'Tyrion Lannister', description: 'Youngest son of Loard Tywin', gender: 'male', house: 'Lannister', } ]; }]); <div> <div ng-repeat="user in users"> <h3>{{user.name}}</h3> <p>{{user.description}}</p> Edit Description: <textarea rows="5" cols="50" ng-model="user.description"> </div> </div> controller view result
  • 30. Scope The scope is used to link the controllers and the views to which they are binded. A controller can add data and function in its scope and then they will be accessible in the view. In our case, we have used in the view a variable named “users" which was created in the scope by the controller “UsersCtrl". A scope can have child scopes which can see the content of the parent scopes. Each directive can create and manage its own scope. The scope also comes with additional operations that can be quite useful to build your application
  • 31. Scope - $watch AngularJS provides the necessary tool to observe the changes on the data of the scope from the controller. With the operation "$watch", a controller can add a listener on an expression of the scope. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) { $scope.users = []; $scope.$watch('users', function (newValue, oldValue) { console.log('The value of "users" has changed'); }, true); }]);
  • 32. Scope - $broadcast and $on AngularJS also gives you access to a system of events and listeners on the scope. You can use the operation "$broadcast" in order to fire an event on a specific scope, then the event will be transmitted to the selected scope and all its children. With $on, you can receive the event. If you want to send an event to the whole application, you can use the root scope by injected the service $rootScope. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.controller('UsersCtrl', ['$scope', function ($scope) { $scope.$on('AngularJSModule.Event', function () { console.log('An event "AngularJSModule.Event" has been fired!'); }); $scope.$broadcast('AngularJSModule.Event'); }]);
  • 33. Services utility components of your application
  • 34. Services Controllers contains the data of the application that should be available to the view. If you have some code that you want to re-use or that you want to separate from a controller, use a service and inject it thanks to dependency injection. Services can be injected into other services, filters, controllers or directives to build more complex components. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.factory('UsersServer', [function () { return {}; }]);
  • 35. Services - public API By using the function "factory", you can create your service and return it manually You can then define the public API of your service and the private functions and variables There are other ways to create your services but we won't see them here. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.factory('UsersServer', [function () { var privateFunction = function () {}; var usersServer = {}; usersServer.publicFunction = function () { privateFunction(); }; return usersServer; }]);
  • 37. Directives Directives are insanely powerful in Angular but it is a bit complex to create an advanced directive. I won't explain here all the options available to create a directive, but here is a simple example. var angularJSModule = angular.module('AngularJSModule', []); angularJSModule.directive('whereIsThePower, [function () { return { template: '<p>Power resides where men believe it resides. No more and no less</p>', replace: true }; }]); <div where-is-the-power></div>
  • 38. One more thing You should never ever ever manipulate the DOM from a controller! respect the separation of concerns, the data in the controller, the behavior in the directives it's easier to test and easier to maintain
  • 39. Wrapping things up As you have seen it during this presentation, Angular is a MVC framework with a strong opinion on how things should be done. It helps you build an application ● testable with dependency injection ● maintainable with small specialized components ● with reusable components ● well architectured (data in controllers, behavior in the directives, utility stuff in services)
  • 40. Frameworks, libraries and tools If you want to build an Angular application, you should have a look at those tools too ● Batarang - chrome extension to debug Angular applications ● Bower - dependency management tooling for front end applications by Twitter ● Grunt - tasks management (minification, autoreload, SASS or CoffeeScript compilation) ● Yeoman - generate preconfigured kickass web applications ● Karma - Angular tests runner ● Angular-ui - collection of Angular directives (datepicker, Google Maps, Bootstrap) ● Restangular - improved Angular services for REST communication
  • 41. Thanks! For more information and regular news about AngularJS, follow me on Twitter or Google+