SlideShare a Scribd company logo
Get rid of controllers in
AngularJS 1.5.x
Start using component directives
Fakiolas Marios - fakiolasmarios@gmail.com / @fakiolinho
Frontend Developer at mist.io, creator of angularjs-recipes.com
What are
component
directives in
AngularJS 1.5 ?
As of AngularJS 1.5.x release a new type of
directives was introduced. These are component
directives.
A component directive is a component with directives
flavor.
This is a huge step which brings us closer to
components logic even in AngularJS 1.5.x
We can now build an AngularJS 1.5.x application by
replacing controllers with components.
So we can prepare even better our old applications
for their upgrade to Angular 2 and its components
ways.
Let’s create
a simple
component
directive
// Create it
angular
.module('myApp')
.component('userGreeting', {
bindings: {
user: '='
},
controller: function() {
var self = this;
self.welcome = 'Welcome ' + self.user.name + '!';
},
template: '<h1>{{$ctrl.welcome}}</h1>'
});
// Use it
<user-greeting user="{name: 'John Doe'}"></user-greeting>
<user-greeting user="{name: 'Jane Doe'}"></user-greeting>
Analyze a
simple
component
directive
name
This is the name of the component and the only
required option. We should pick wisely a camel-case
name to register our component and then call it into
action using this. Be careful because it always maps
to a dash-case component:
angular
.module('myApp')
.component('userGreeting', {
...
});
<user-greeting user="{name: 'John Doe'}"></user-greeting>
Analyze a
simple
component
directive
bindings
This an optional parameter and it is the way to
define DOM attribute binding to component
properties. Component properties are always bound
to the component controller.
angular
.module('myApp')
.component('userGreeting', {
bindings: {
user: '='
},
...
});
<user-greeting user="{name: 'John Doe'}"></user-greeting>
Analyze a
simple
component
directive
controller
This is an optional parameter and by default an
empty function is registered. Here we can use all
attributes passed with bindings and run some logic.
angular
.module('myApp')
.component('userGreeting', {
bindings: {
user: '='
},
controller: function() {
var self = this;
self.welcome = 'Welcome ' + self.user.name + '!';
}
...
});
Analyze a
simple
component
directive
template
This is an optional parameter which returns an
empty string by default. We can register with it a
html template as the content of our component.
Check out offered $ctrl as a controller’s alias.
angular
.module('myApp')
.component('userGreeting', {
bindings: {
user: '='
},
controller: function() {
var self = this;
self.welcome = 'Welcome ' + self.user.name + '!';
},
template: '<h1>{{$ctrl.welcome}}</h1>'
});
Analyze a
simple
component
directive
templateUrl
We could use this to call into action an external
html file as our component’s template.
angular
.module('myApp')
.component('userGreeting', {
bindings: {
user: '='
},
controller: function() {
var self = this;
self.welcome = 'Welcome ' + self.user.name + '!';
},
templateUrl: 'greeting.html'
});
Are you
still ok?
Let’s create
a simple
Blog
application
with
component
directives
https://github.com/Athens-AngularJS-Meetup/blog
Routing with
component
directives
// Routing using components instead of controllers
angular
.module('myApp')
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
resolve: {
posts: function(Post) {
return Post.all();
}
},
template: '<posts posts="$resolve.posts"></posts>'
})
...
Declaring
posts
component
// Posts list component
angular
.module('myApp')
.component('posts', {
templateUrl: 'app/templates/posts.html',
bindings: {
posts: '='
},
controller: function() {
var self = this;
self.posts = self.posts.slice(0, 5);
}
});
Declaring
posts list
and post-
item
templates
// Posts list template
<section id="posts">
<post-item post="post" ng-repeat="post in $ctrl.posts"></post-item>
</section>
// Post list item template
<div class="post-item card">
<img ng-src="{{$ctrl.img}}" alt="{{$ctrl.post.title}}" />
<div class="card-body">
<h4>{{$ctrl.post.title}}</h4>
<hr>
<p>{{$ctrl.post.body}}</p>
<a ng-href="#/posts/{{$ctrl.post.id}}" class="btn">Read
More</a>
</div>
</div>
Declaring
post-item
component
// Post item component
angular
.module('myApp')
.component('postItem', {
templateUrl: 'app/templates/post-item.html',
bindings: {
post: '<'
},
controller: function() {
var self = this;
self.img = 'http://lorempixel.com/600/300/city/';
}
});
Declaring
Post factory
// Posts factory
angular
.module('myApp')
.factory('Post', ['$http', function($http) {
var service = {
all: all,
get: get
};
return service;
function all() {
return $http
.get('http://jsonplaceholder.typicode.com/posts')
.then(function(data) {
return data.data;
});
}
...
Create even
more
components
like social-
icons
// Declare the component
angular
.module('myApp')
.component('socialIcons', {
templateUrl: 'app/templates/social-icons.html'
});
// Declare its template
<ul class="social-icons">
<li>
<a href="#"><i class="fa fa-twitter"></i></a>
</li>
...
</ul>
// Use the component
<social-icons></social-icons>
Components
data
bindings
overview
Components
bindings
type does
matter a lot
bindings: {
// Two way data-bindings (avoid usage)
posts: '=',
// One way data-bindings
// Preferable for Objects (highly proposed)
post: '<',
// Preferable for simple Strings
name: '@',
// Outputs data-bindings
onEdit: '&'
}
Components
bindings
type does
matter a lot
Ideally, the whole application should be a tree of
components that implement clearly defined inputs
and outputs, and minimize two-way data binding.
That way, it's easier to predict when data changes
and what the state of a component is.
Inputs should be using < and @ bindings. The <
symbol denotes one-way bindings (available since
1.5). The difference to = is that the bound properties
in the component scope are not watched, which
means if you assign a new value to the property in
the component scope, it will not update the parent
scope.
Components
bindings
type does
matter a lot
Note however, that both parent and component
scope reference the same object, so if you are
changing object properties or array elements in the
component, the parent will still reflect that change.
The general rule should therefore be to never
change an object or array property in the component
scope.
Components
cooperation
Of course components have outputs too. These are
also declared in bindings and we use them to inform
a parent component regarding an edit / delete /
update action we want to execute.
Data flow always from parents to children and
children never edit their inputs but emit the right
callback events backwards to their parents
requesting an action.
Outputs are realized with & bindings, which function
as callbacks to component events.
That way, the parent component can decide what to
do with the event (e.g. delete an item or update the
properties)
Components
cooperation
example
// Child's input / output bindings
bindings: {
task: '<',
onDelete: '&'
}
// Child's template
<p>{{$ctrl.post.title}}</p>
<button ng-click="$ctrl.onDelete({post: $ctrl.post})">Delete</button>
//Parent's template
<section id="posts">
<post-item post="post" on-delete="$ctrl.deletePost(post)" ng-repeat="post
in $ctrl.posts"></post-item>
</section>
// Parent's controller
ctrl.deletePost(post) {
...
}
Get rid of controllers in angular 1.5.x start using component directives

More Related Content

What's hot (20)

PPTX
AngularJS2 / TypeScript / CLI
Domenico Rutigliano
 
PPTX
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
PPTX
Dive into Angular, part 3: Performance
Oleksii Prohonnyi
 
PDF
Angular from Scratch
Christian Lilley
 
PPTX
AngularJs presentation
Phan Tuan
 
PDF
Redux and context api with react native app introduction, use cases, implemen...
Katy Slemon
 
PDF
Angular2 workshop
Nir Kaufman
 
PDF
The productive developer guide to Angular 2
Maurice De Beijer [MVP]
 
PDF
Angular 2 - An Introduction
NexThoughts Technologies
 
PDF
Angular 4 for Java Developers
Yakov Fain
 
PDF
Extending Kubernetes with Operators
peychevi
 
PPTX
React js programming concept
Tariqul islam
 
PDF
JOSA TechTalks - Better Web Apps with React and Redux
Jordan Open Source Association
 
PPTX
Angular2 + rxjs
Christoffer Noring
 
PDF
Angular Dependency Injection
Nir Kaufman
 
PDF
React native app with type script tutorial
Katy Slemon
 
PDF
Introduction to Angular 2
Naveen Pete
 
PDF
Top 7 Angular Best Practices to Organize Your Angular App
Katy Slemon
 
PDF
Getting Started with React-Nathan Smith
TandemSeven
 
PPTX
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
AngularJS2 / TypeScript / CLI
Domenico Rutigliano
 
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
Dive into Angular, part 3: Performance
Oleksii Prohonnyi
 
Angular from Scratch
Christian Lilley
 
AngularJs presentation
Phan Tuan
 
Redux and context api with react native app introduction, use cases, implemen...
Katy Slemon
 
Angular2 workshop
Nir Kaufman
 
The productive developer guide to Angular 2
Maurice De Beijer [MVP]
 
Angular 2 - An Introduction
NexThoughts Technologies
 
Angular 4 for Java Developers
Yakov Fain
 
Extending Kubernetes with Operators
peychevi
 
React js programming concept
Tariqul islam
 
JOSA TechTalks - Better Web Apps with React and Redux
Jordan Open Source Association
 
Angular2 + rxjs
Christoffer Noring
 
Angular Dependency Injection
Nir Kaufman
 
React native app with type script tutorial
Katy Slemon
 
Introduction to Angular 2
Naveen Pete
 
Top 7 Angular Best Practices to Organize Your Angular App
Katy Slemon
 
Getting Started with React-Nathan Smith
TandemSeven
 
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 

Viewers also liked (16)

PDF
Reactive.architecture.with.Angular
Evan Schultz
 
PDF
Ionic
Mike Hartington
 
PDF
Ionic: Hybrid Mobile Apps... made simple
Commit University
 
PPTX
Comercio electronico
mariangelarod
 
DOCX
Derechos del niño
Tony Hotter
 
PDF
Ritusmoi_Kaushik_Resume
Ritusmoi Kaushik
 
PPTX
Buenas tortas
Cristian Rendon
 
PDF
Apresentação Renova - Institucional
mgboni
 
PPTX
музей охраны природы
school68vrn
 
PDF
Nâng cao năng lực của các trường cao đẳng nghề vùng đồng bằng sông h...
https://www.facebook.com/garmentspace
 
PDF
Building cross platform app with Xamarin Forms
Aurelian Maga
 
PDF
Ti g4 final
jairosic1530
 
PDF
Angular 2 Component Communication - Talk by Rob McDiarmid
Amrita Chopra
 
PDF
Dislexia, disgrafía y dificultades habituales 6
gesfomediaeducacion
 
PDF
Hybrid Apps with Ionic Framework
Bramus Van Damme
 
PPS
Misses
Claudio Juliana
 
Reactive.architecture.with.Angular
Evan Schultz
 
Ionic: Hybrid Mobile Apps... made simple
Commit University
 
Comercio electronico
mariangelarod
 
Derechos del niño
Tony Hotter
 
Ritusmoi_Kaushik_Resume
Ritusmoi Kaushik
 
Buenas tortas
Cristian Rendon
 
Apresentação Renova - Institucional
mgboni
 
музей охраны природы
school68vrn
 
Nâng cao năng lực của các trường cao đẳng nghề vùng đồng bằng sông h...
https://www.facebook.com/garmentspace
 
Building cross platform app with Xamarin Forms
Aurelian Maga
 
Ti g4 final
jairosic1530
 
Angular 2 Component Communication - Talk by Rob McDiarmid
Amrita Chopra
 
Dislexia, disgrafía y dificultades habituales 6
gesfomediaeducacion
 
Hybrid Apps with Ionic Framework
Bramus Van Damme
 
Ad

Similar to Get rid of controllers in angular 1.5.x start using component directives (20)

PPTX
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
PPTX
angularJs Workshop
Ran Wahle
 
PDF
Angular Rebooted: Components Everywhere - Carlo Bonamico, Sonia Pini - Codemo...
Codemotion
 
PDF
Angular Rebooted: Components Everywhere
Carlo Bonamico
 
PPTX
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
PDF
Angularjs
Ynon Perek
 
PDF
Angular.js Primer in Aalto University
SC5.io
 
PDF
Angular custom directives
Alexe Bogdan
 
PDF
AngularJS: an introduction
Luigi De Russis
 
PPTX
Intro to AngularJs
SolTech, Inc.
 
PPTX
Angular Workshop_Sarajevo2
Christoffer Noring
 
PDF
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
PPT
Angular js
Hritesh Saha
 
PPT
Angular js
yogi_solanki
 
PDF
Angular Directives from Scratch
Christian Lilley
 
PPTX
Introduction to AngularJs
murtazahaveliwala
 
PPTX
Introduction to Angular JS
Santhosh Kumar Srinivasan
 
PPTX
Angular workshop - Full Development Guide
Nitin Giri
 
PPTX
AngularJS
LearningTech
 
PPTX
Angular Presentation
Adam Moore
 
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
angularJs Workshop
Ran Wahle
 
Angular Rebooted: Components Everywhere - Carlo Bonamico, Sonia Pini - Codemo...
Codemotion
 
Angular Rebooted: Components Everywhere
Carlo Bonamico
 
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
Angularjs
Ynon Perek
 
Angular.js Primer in Aalto University
SC5.io
 
Angular custom directives
Alexe Bogdan
 
AngularJS: an introduction
Luigi De Russis
 
Intro to AngularJs
SolTech, Inc.
 
Angular Workshop_Sarajevo2
Christoffer Noring
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
Angular js
Hritesh Saha
 
Angular js
yogi_solanki
 
Angular Directives from Scratch
Christian Lilley
 
Introduction to AngularJs
murtazahaveliwala
 
Introduction to Angular JS
Santhosh Kumar Srinivasan
 
Angular workshop - Full Development Guide
Nitin Giri
 
AngularJS
LearningTech
 
Angular Presentation
Adam Moore
 
Ad

Recently uploaded (20)

PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
Digital water marking system project report
Kamal Acharya
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
Distribution reservoir and service storage pptx
dhanashree78
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
Digital water marking system project report
Kamal Acharya
 

Get rid of controllers in angular 1.5.x start using component directives

  • 1. Get rid of controllers in AngularJS 1.5.x Start using component directives Fakiolas Marios - [email protected] / @fakiolinho Frontend Developer at mist.io, creator of angularjs-recipes.com
  • 2. What are component directives in AngularJS 1.5 ? As of AngularJS 1.5.x release a new type of directives was introduced. These are component directives. A component directive is a component with directives flavor. This is a huge step which brings us closer to components logic even in AngularJS 1.5.x We can now build an AngularJS 1.5.x application by replacing controllers with components. So we can prepare even better our old applications for their upgrade to Angular 2 and its components ways.
  • 3. Let’s create a simple component directive // Create it angular .module('myApp') .component('userGreeting', { bindings: { user: '=' }, controller: function() { var self = this; self.welcome = 'Welcome ' + self.user.name + '!'; }, template: '<h1>{{$ctrl.welcome}}</h1>' }); // Use it <user-greeting user="{name: 'John Doe'}"></user-greeting> <user-greeting user="{name: 'Jane Doe'}"></user-greeting>
  • 4. Analyze a simple component directive name This is the name of the component and the only required option. We should pick wisely a camel-case name to register our component and then call it into action using this. Be careful because it always maps to a dash-case component: angular .module('myApp') .component('userGreeting', { ... }); <user-greeting user="{name: 'John Doe'}"></user-greeting>
  • 5. Analyze a simple component directive bindings This an optional parameter and it is the way to define DOM attribute binding to component properties. Component properties are always bound to the component controller. angular .module('myApp') .component('userGreeting', { bindings: { user: '=' }, ... }); <user-greeting user="{name: 'John Doe'}"></user-greeting>
  • 6. Analyze a simple component directive controller This is an optional parameter and by default an empty function is registered. Here we can use all attributes passed with bindings and run some logic. angular .module('myApp') .component('userGreeting', { bindings: { user: '=' }, controller: function() { var self = this; self.welcome = 'Welcome ' + self.user.name + '!'; } ... });
  • 7. Analyze a simple component directive template This is an optional parameter which returns an empty string by default. We can register with it a html template as the content of our component. Check out offered $ctrl as a controller’s alias. angular .module('myApp') .component('userGreeting', { bindings: { user: '=' }, controller: function() { var self = this; self.welcome = 'Welcome ' + self.user.name + '!'; }, template: '<h1>{{$ctrl.welcome}}</h1>' });
  • 8. Analyze a simple component directive templateUrl We could use this to call into action an external html file as our component’s template. angular .module('myApp') .component('userGreeting', { bindings: { user: '=' }, controller: function() { var self = this; self.welcome = 'Welcome ' + self.user.name + '!'; }, templateUrl: 'greeting.html' });
  • 11. Routing with component directives // Routing using components instead of controllers angular .module('myApp') .config(['$routeProvider', function($routeProvider) { $routeProvider .when('/', { resolve: { posts: function(Post) { return Post.all(); } }, template: '<posts posts="$resolve.posts"></posts>' }) ...
  • 12. Declaring posts component // Posts list component angular .module('myApp') .component('posts', { templateUrl: 'app/templates/posts.html', bindings: { posts: '=' }, controller: function() { var self = this; self.posts = self.posts.slice(0, 5); } });
  • 13. Declaring posts list and post- item templates // Posts list template <section id="posts"> <post-item post="post" ng-repeat="post in $ctrl.posts"></post-item> </section> // Post list item template <div class="post-item card"> <img ng-src="{{$ctrl.img}}" alt="{{$ctrl.post.title}}" /> <div class="card-body"> <h4>{{$ctrl.post.title}}</h4> <hr> <p>{{$ctrl.post.body}}</p> <a ng-href="#/posts/{{$ctrl.post.id}}" class="btn">Read More</a> </div> </div>
  • 14. Declaring post-item component // Post item component angular .module('myApp') .component('postItem', { templateUrl: 'app/templates/post-item.html', bindings: { post: '<' }, controller: function() { var self = this; self.img = 'http://lorempixel.com/600/300/city/'; } });
  • 15. Declaring Post factory // Posts factory angular .module('myApp') .factory('Post', ['$http', function($http) { var service = { all: all, get: get }; return service; function all() { return $http .get('http://jsonplaceholder.typicode.com/posts') .then(function(data) { return data.data; }); } ...
  • 16. Create even more components like social- icons // Declare the component angular .module('myApp') .component('socialIcons', { templateUrl: 'app/templates/social-icons.html' }); // Declare its template <ul class="social-icons"> <li> <a href="#"><i class="fa fa-twitter"></i></a> </li> ... </ul> // Use the component <social-icons></social-icons>
  • 18. Components bindings type does matter a lot bindings: { // Two way data-bindings (avoid usage) posts: '=', // One way data-bindings // Preferable for Objects (highly proposed) post: '<', // Preferable for simple Strings name: '@', // Outputs data-bindings onEdit: '&' }
  • 19. Components bindings type does matter a lot Ideally, the whole application should be a tree of components that implement clearly defined inputs and outputs, and minimize two-way data binding. That way, it's easier to predict when data changes and what the state of a component is. Inputs should be using < and @ bindings. The < symbol denotes one-way bindings (available since 1.5). The difference to = is that the bound properties in the component scope are not watched, which means if you assign a new value to the property in the component scope, it will not update the parent scope.
  • 20. Components bindings type does matter a lot Note however, that both parent and component scope reference the same object, so if you are changing object properties or array elements in the component, the parent will still reflect that change. The general rule should therefore be to never change an object or array property in the component scope.
  • 21. Components cooperation Of course components have outputs too. These are also declared in bindings and we use them to inform a parent component regarding an edit / delete / update action we want to execute. Data flow always from parents to children and children never edit their inputs but emit the right callback events backwards to their parents requesting an action. Outputs are realized with & bindings, which function as callbacks to component events. That way, the parent component can decide what to do with the event (e.g. delete an item or update the properties)
  • 22. Components cooperation example // Child's input / output bindings bindings: { task: '<', onDelete: '&' } // Child's template <p>{{$ctrl.post.title}}</p> <button ng-click="$ctrl.onDelete({post: $ctrl.post})">Delete</button> //Parent's template <section id="posts"> <post-item post="post" on-delete="$ctrl.deletePost(post)" ng-repeat="post in $ctrl.posts"></post-item> </section> // Parent's controller ctrl.deletePost(post) { ... }