SlideShare a Scribd company logo
AngularJS
building web apps like software
Brent Goldstein
brentlanegold@gmail.com
Some of the software I've written
Applesoft Basic
Pascal
8088 Assembler
FORTRAN 77
ADA
'C'
PERL
C++
C#
Ruby
Javascript
AppleII+
Mainframe
Embedded
Mainframe
Minicomputer
HP/Sun Unix
HP/Sun Unix
HP/Sun Unix
PC
Linux
Linux
nada
nada
nada
nada
nada
X/Motif / OpenGL
Perl-CGI
X/Motif
WinForms
Rails
AngularJS
Languages / Frameworks / Platforms
what, no Java?!...
AngularJS is like writing 'software'
Angular follows patterns of software development
- encapsulation
- componentization / reusability
- separation of model from view w/binding
- but, there is a client-side model
Kind of opposite to 'web page' design
Not really friendly to 'external jquery'
Need to think like building 'widgets'
Directives and Controllers
Directive is intended drive reusable,
encapsulated rendering
Central idea, declare behavior in HTML, but
execute in code
Where does the code go? In a custom
controller inside the directive
Need to consider scope
Directives can have private scope
This is important, also provides for
encapsulated behavior. Basically a boundary.
The directive's custom controller has direct
access to the directive's scope. -- Just like any
other controller, really.
Basic Structure
myApp.directive('directiveName', function() {
return {
restrict: 'E',
scope: {
varA: '=', // 2-way binding
varB: '@', // 1-way binding
},
controller: function($scope) {
// declare reusable functions
$scope.myFunc = function(a,b,c){
$scope.varA = a*b/c; // neato
}
// do some other things here, but executes only once
$scope.someVal = varB * 2.17;
},
template: "<div> Html can go here </div>"
// templateUrl: /path/to/html/partial.html
};
});
Calling the directive
You can pass variables from the calling scope
into the directive scope
<my-directive var-a="angular exp"
var-b="angular exp">
</my-directive>
Note the name-with-dashes in attributes maps
to camelCase in the directive scope
Use Case - Button Groups
Generate a set of radio buttons that are
decoupled from the specific scenario
Wanted a directive that:
- looped through a list of values
- created the buttons
- attached activate handlers to each button
- exposed the current active value
Two scopes, two controllers
HTML Code
<button-group
attr1="list" attr2="handlers">
</button-group>
Directive Code
myApp.directive(buttonGroup, function()
{
// interior scope & controller
...
});
App Controller Code
myApp.controller('mainController',
function mainController($scope){
});
Using callback functions
Sometimes you want to call a function, not set
a value directly.
You can actually pass functions to the directive
But, is there a way to create a more
streamlined payload / signature?
Yes, we can just bundled into an object and call
inside the directive
Demo for dynamic button directive
The disclaimer - NNYBCBIW
Not necessarily your best code, but it works
From a 'database' of movies, generate buttons that trigger
the display of movie info
Code avail from:
https://github.com/brentlane/tigley
(tigley is the name of my cat...)
Route Resolver
How do you trigger an action when a page is
finished loading?
Yep, you guessed it, the route resolver
From the route config you can specify a
function that will be called when the route is
complete, page is done loading
Basic Structure
$routeProvider.when('/somepage', {
templateUrl: 'partials/mypa.html',
resolve: {
resolvePage : [''myResolveFunc, function(myResolveFunc) {
var dataToPass = { somedata: "yadda", moredata: "wubba"};
myResolveFunc.doSomething(dataToPass);
}]}
});
Pretty straightforward, specify a callback function and pass any data
As this is Angular, you could also use dependency injection to access outside
data in the resolve call
Use Case - Dynamic Header
Angular has views, which are great
But, how to change the state of html elements outside of
the view, like a header?
Yep, let's use the route resolver. It can trigger the behavior
Then we can mediate through a service which broadcasts a
message, which is picked up by a controller that's outside
of the view.
Page resolve flow to update header
Service handles communicating to controller, passes data
to configure the header based on route
HTML Page
The View
Route Resolve
1) resolve view
2) trigger resolve func
Broadcast Service
header
Outer Page Controller
Demo for route resolve
The same disclaimer - NNYBCBIW
Not necessarily your best code, but it works
Very simple, a skeleton app with a couple views, the
header text changes for each view
Code at:
https://github.com/brentlane/tigley

More Related Content

PPTX
Angular.js Directives for Interactive Web Applications
PDF
Integrating Angular js & three.js
PDF
Workshop 9: BackboneJS y patrones MVC
KEY
AngularJS for designers and developers
PPTX
Angular JS - Introduction
PDF
Marionette: the Backbone framework
PPTX
Angular js
PDF
AngularJS Basic Training
Angular.js Directives for Interactive Web Applications
Integrating Angular js & three.js
Workshop 9: BackboneJS y patrones MVC
AngularJS for designers and developers
Angular JS - Introduction
Marionette: the Backbone framework
Angular js
AngularJS Basic Training

What's hot (20)

PPTX
Angularjs Basics
PDF
Angularjs architecture
PDF
Introduction to AngularJS
PDF
Building a Startup Stack with AngularJS
PDF
Intro to Angular.JS Directives
PDF
Angular Directives from Scratch
PDF
AngularJS best-practices
PDF
AngularJS Basics
PDF
Workshop 16: EmberJS Parte I
PPTX
Introduction to Angularjs
PPTX
Backbone/Marionette recap [2015]
PPTX
Web Components
PPTX
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
PDF
Introduction to VueJS & Vuex
PPTX
Polymer and web component
PPTX
AngularJs
PDF
AngularJS Best Practices
PPTX
Intro to AngularJs
PPTX
AngularJS Beginners Workshop
Angularjs Basics
Angularjs architecture
Introduction to AngularJS
Building a Startup Stack with AngularJS
Intro to Angular.JS Directives
Angular Directives from Scratch
AngularJS best-practices
AngularJS Basics
Workshop 16: EmberJS Parte I
Introduction to Angularjs
Backbone/Marionette recap [2015]
Web Components
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
AngularJS - What is it & Why is it awesome ? (with demos)
Introduction to VueJS & Vuex
Polymer and web component
AngularJs
AngularJS Best Practices
Intro to AngularJs
AngularJS Beginners Workshop
Ad

Similar to AngularJS preso with directives and route resolve (20)

PPTX
Angular js 1.3 presentation for fed nov 2014
PPTX
AngularJs Workshop SDP December 28th 2014
PPTX
Angular js for Beginnners
PPT
Angular js
PDF
AngularJS Basics and Best Practices - CC FE &UX
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
PPTX
Module2
PPTX
angularJs Workshop
PPTX
Angular workshop - Full Development Guide
PDF
AngularJS Workshop
PPTX
Angular js workshop
PDF
AngularJS: an introduction
PPT
Angular js
PPT
Introduction to AngularJS
PPTX
AngularJS Fundamentals + WebAPI
PDF
AngularJS for Web and Mobile
PPTX
Angular Presentation
PPTX
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
Angular js 1.3 presentation for fed nov 2014
AngularJs Workshop SDP December 28th 2014
Angular js for Beginnners
Angular js
AngularJS Basics and Best Practices - CC FE &UX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Module2
angularJs Workshop
Angular workshop - Full Development Guide
AngularJS Workshop
Angular js workshop
AngularJS: an introduction
Angular js
Introduction to AngularJS
AngularJS Fundamentals + WebAPI
AngularJS for Web and Mobile
Angular Presentation
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
Teaching material agriculture food technology
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Spectroscopy.pptx food analysis technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PPTX
Machine Learning_overview_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectroscopy.pptx food analysis technology
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
Machine Learning_overview_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...

AngularJS preso with directives and route resolve

  • 1. AngularJS building web apps like software Brent Goldstein brentlanegold@gmail.com
  • 2. Some of the software I've written Applesoft Basic Pascal 8088 Assembler FORTRAN 77 ADA 'C' PERL C++ C# Ruby Javascript AppleII+ Mainframe Embedded Mainframe Minicomputer HP/Sun Unix HP/Sun Unix HP/Sun Unix PC Linux Linux nada nada nada nada nada X/Motif / OpenGL Perl-CGI X/Motif WinForms Rails AngularJS Languages / Frameworks / Platforms what, no Java?!...
  • 3. AngularJS is like writing 'software' Angular follows patterns of software development - encapsulation - componentization / reusability - separation of model from view w/binding - but, there is a client-side model Kind of opposite to 'web page' design Not really friendly to 'external jquery' Need to think like building 'widgets'
  • 4. Directives and Controllers Directive is intended drive reusable, encapsulated rendering Central idea, declare behavior in HTML, but execute in code Where does the code go? In a custom controller inside the directive
  • 5. Need to consider scope Directives can have private scope This is important, also provides for encapsulated behavior. Basically a boundary. The directive's custom controller has direct access to the directive's scope. -- Just like any other controller, really.
  • 6. Basic Structure myApp.directive('directiveName', function() { return { restrict: 'E', scope: { varA: '=', // 2-way binding varB: '@', // 1-way binding }, controller: function($scope) { // declare reusable functions $scope.myFunc = function(a,b,c){ $scope.varA = a*b/c; // neato } // do some other things here, but executes only once $scope.someVal = varB * 2.17; }, template: "<div> Html can go here </div>" // templateUrl: /path/to/html/partial.html }; });
  • 7. Calling the directive You can pass variables from the calling scope into the directive scope <my-directive var-a="angular exp" var-b="angular exp"> </my-directive> Note the name-with-dashes in attributes maps to camelCase in the directive scope
  • 8. Use Case - Button Groups Generate a set of radio buttons that are decoupled from the specific scenario Wanted a directive that: - looped through a list of values - created the buttons - attached activate handlers to each button - exposed the current active value
  • 9. Two scopes, two controllers HTML Code <button-group attr1="list" attr2="handlers"> </button-group> Directive Code myApp.directive(buttonGroup, function() { // interior scope & controller ... }); App Controller Code myApp.controller('mainController', function mainController($scope){ });
  • 10. Using callback functions Sometimes you want to call a function, not set a value directly. You can actually pass functions to the directive But, is there a way to create a more streamlined payload / signature? Yes, we can just bundled into an object and call inside the directive
  • 11. Demo for dynamic button directive The disclaimer - NNYBCBIW Not necessarily your best code, but it works From a 'database' of movies, generate buttons that trigger the display of movie info Code avail from: https://github.com/brentlane/tigley (tigley is the name of my cat...)
  • 12. Route Resolver How do you trigger an action when a page is finished loading? Yep, you guessed it, the route resolver From the route config you can specify a function that will be called when the route is complete, page is done loading
  • 13. Basic Structure $routeProvider.when('/somepage', { templateUrl: 'partials/mypa.html', resolve: { resolvePage : [''myResolveFunc, function(myResolveFunc) { var dataToPass = { somedata: "yadda", moredata: "wubba"}; myResolveFunc.doSomething(dataToPass); }]} }); Pretty straightforward, specify a callback function and pass any data As this is Angular, you could also use dependency injection to access outside data in the resolve call
  • 14. Use Case - Dynamic Header Angular has views, which are great But, how to change the state of html elements outside of the view, like a header? Yep, let's use the route resolver. It can trigger the behavior Then we can mediate through a service which broadcasts a message, which is picked up by a controller that's outside of the view.
  • 15. Page resolve flow to update header Service handles communicating to controller, passes data to configure the header based on route HTML Page The View Route Resolve 1) resolve view 2) trigger resolve func Broadcast Service header Outer Page Controller
  • 16. Demo for route resolve The same disclaimer - NNYBCBIW Not necessarily your best code, but it works Very simple, a skeleton app with a couple views, the header text changes for each view Code at: https://github.com/brentlane/tigley