SlideShare una empresa de Scribd logo
1 de 24
UI-Router 
The hero we need… 
Loc Nguyen
• 6:30 - 7:00 – Food and networking 
• 7:00 - 7:05 – Announcements, LoanNow intro 
• 7:05 - 7:30 – Restangular Lightning Talk 
• 7:30 - 8:15 – UI-Router 
• 8:15 - 8:25 – Wrap up and raffle
<ng-selfie /> 
• Multi-platform SW engineering geek => 
Java, Ruby, JavaScript, C#, Node 
• ~1.5 years of AngularJS experience => 
mostly freelancing 
• Preferred Ember at first! 
• Speaking at OC Java UG in October
ngRoute :-( 
• Transitions by URL 
• Work-arounds to handle nested views 
• Directives 
• ngInclude 
• ngSwitch
UI-Router (>^_^)> 
• Transitions by state rather then by URL 
• Define and design states your application can be in 
• Nested states!
States 
• Not all states need a URL, e.g. a modal, section 
expansion 
• Can configure in any order 
• Can configure across modules
Nested States 
• Can configure child states before parents 
• A child state and its ancestors are active 
• Inherit parent dependencies using the resolve map
UI-Router Services 
• $stateProvider – define state transitions 
• $state – transition to another state, check what the 
current state is 
• $stateParams – get route and query parameter values for 
the current state
Simple State Configuration 
angular.module('helloApp').config(function($stateProvider) { 
$stateProvider.state('login', { 
url: '/login', 
templateUrl: 'views/login.html' 
}) 
});
Diff with ngRoute 
angular.module('helloApp').config(function($stateProvider) { 
$stateProvider.state('login', { 
url: '/login', 
templateUrl: 'views/login.html' 
}) 
}); 
angular.module('helloApp').config(function($routeProvider) { 
$routeProvider.when('/login', { 
templateUrl: 'views/login.html' 
}) 
});
Nested State Configuration 
angular.module('helloApp').config(function ($stateProvider) { 
$stateProvider.state('app', { 
template: '<html><body><header>you fancy</header>' + 
'<ui-view></ui-view></body></html>' 
}).state('app.login', { 
url: '/login', 
templateUrl: 'views/login.html' 
}); 
});
Transitioning States 
$state.go('login'); 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('acount', { 
url: '/account/:id?showDetails', 
templateUrl: 'views/account.html' 
}); 
}); 
$state.go('account', { id: 47, showDetails: true });
In & Out Callbacks 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('app.acount', { 
url: '/account/:id', 
templateUrl: 'views/account.html', 
onEnter: function () { 
console.log('Google Analytics, open modal etc'); 
}, 
onExit: function () { 
console.log('clean up, animate etc'); 
} 
}); 
});
UI-Router Directives 
• uiSref – declarative link to a state 
• uiSrefActive – adds CSS classes when a state is active 
• uiView – where to place the state template
UI-Router Directives 
• uiSref is UI-Router’s ngHref 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('acount', { 
url: '/account/:id?showDetails', 
templateUrl: 'views/account.html' 
}); 
}); 
<a ui-sref="login">Login</a> 
<a ui-sref="account({ id: 47, showDetails: true })">Account</a>
UI-Router Directives 
• uiView is UI-Router’s version of ngView 
• Tells UI-Router where to inject our views 
• Supports named views 
<html> 
<body> 
<header></header> 
<ui-view></ui-view> 
</body> 
</html>
Named Views 
• More than one uiView in a template 
• Flexible and dynamic layouts 
<html> 
<body> 
<ui-view="header"></ui-view> 
<ui-view="sideNav"></ui-view> 
<ui-view="mainContent"></ui-view> 
</body> 
</html>
Named Views 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('login', { 
url: '/login', 
views: { 
'header': { templateUrl: 'views/unauth-header.html' }, 
'sideNav': { templateUrl: 'views/unauth-sidenav.html' }, 
'content': { templateUrl: 'views/login.html' } 
} 
}); 
});
Resolve & Controllers 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('app.acount', { 
url: '/account/:id', 
templateUrl: 'views/account.html', 
resolve: { 
account: function ($http, $stateParams) { 
return $http.get('/api/account/' + $stateParams.id); 
} 
}, 
controller: function (account) { … } 
controller: 'AccountController' 
controller: ‘AccountController as account' 
}); 
});
Nested Resolve & Controllers 
angular.module('sampleApp').config(function ($stateProvider) { 
$stateProvider.state('account', { 
url: '/account/:id', 
templateUrl: 'views/account.html', 
resolve: { 
account: function ($http, $stateParams) { … } 
} 
}) 
.state('account.details', { 
controller: function (account, DetailService) { … } 
}); 
});
And more… 
• Regex parameters: 
url: “/contacts/{contactId:[0-9]{1,8}}" 
• $urlRouterProvider – watches $location and matches 
against URL configurations
Resources 
• Egghead.io UI-Router Cheat sheet: 
http://goo.gl/ZcL0dv 
• UI-Router at CincyNG meetup: 
https://www.youtube.com/watch?v=lBqiZSemrqg 
• UI-Router extras: 
https://github.com/christopherthielen/ui-router-extras
Didn't win? Get a HUGE discount on the course by visiting: 
http://tinyurl.com/AngularJSJumpstart
UI-Router

Más contenido relacionado

La actualidad más candente

Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS RoutingEgor Miasnikov
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationDan Wahlin
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationEyal Vardi
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorialClaude Tech
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routingBrajesh Yadav
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJSLoc Nguyen
 
Understanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeUnderstanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeBrajesh Yadav
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJSBrajesh Yadav
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explainedRamesh BN
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascriptaglemann
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JSAlwyn Wymeersch
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and ModernizrJussi Pohjolainen
 

La actualidad más candente (20)

Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJS
 
Understanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeUnderstanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scope
 
Built in filters
Built in filtersBuilt in filters
Built in filters
 
J queryui
J queryuiJ queryui
J queryui
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explained
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JS
 
Directives
DirectivesDirectives
Directives
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
 
JQuery
JQueryJQuery
JQuery
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 

Destacado

Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced RoutingAlexe Bogdan
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-frameworkSakthi Bro
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentationJohn Staveley
 
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
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 

Destacado (9)

Intro to UI-Router/TypeScript
Intro to UI-Router/TypeScriptIntro to UI-Router/TypeScript
Intro to UI-Router/TypeScript
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 

Similar a UI-Router

AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014FalafelSoftware
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSDeepu S Nath
 
MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)Chris Clarke
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java DevelopersLoc Nguyen
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
Angular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решенияAngular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решенияOlga Lavrentieva
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docsAbhi166803
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaExoLeaders.com
 
The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015Matt Raible
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish MinutesDan Wahlin
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSbuttyx
 
Sharing Data between controllers in different ways.
Sharing Data between controllers in different ways.Sharing Data between controllers in different ways.
Sharing Data between controllers in different ways.Amar Shukla
 
Different way to share data between controllers in angular js
Different way to share data between controllers in angular jsDifferent way to share data between controllers in angular js
Different way to share data between controllers in angular jscodeandyou forums
 

Similar a UI-Router (20)

AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
Angular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решенияAngular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решения
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docs
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angularjs
AngularjsAngularjs
Angularjs
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Sharing Data between controllers in different ways.
Sharing Data between controllers in different ways.Sharing Data between controllers in different ways.
Sharing Data between controllers in different ways.
 
Different way to share data between controllers in angular js
Different way to share data between controllers in angular jsDifferent way to share data between controllers in angular js
Different way to share data between controllers in angular js
 

Último

Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 

Último (20)

Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 

UI-Router

  • 1. UI-Router The hero we need… Loc Nguyen
  • 2. • 6:30 - 7:00 – Food and networking • 7:00 - 7:05 – Announcements, LoanNow intro • 7:05 - 7:30 – Restangular Lightning Talk • 7:30 - 8:15 – UI-Router • 8:15 - 8:25 – Wrap up and raffle
  • 3. <ng-selfie /> • Multi-platform SW engineering geek => Java, Ruby, JavaScript, C#, Node • ~1.5 years of AngularJS experience => mostly freelancing • Preferred Ember at first! • Speaking at OC Java UG in October
  • 4. ngRoute :-( • Transitions by URL • Work-arounds to handle nested views • Directives • ngInclude • ngSwitch
  • 5. UI-Router (>^_^)> • Transitions by state rather then by URL • Define and design states your application can be in • Nested states!
  • 6. States • Not all states need a URL, e.g. a modal, section expansion • Can configure in any order • Can configure across modules
  • 7. Nested States • Can configure child states before parents • A child state and its ancestors are active • Inherit parent dependencies using the resolve map
  • 8. UI-Router Services • $stateProvider – define state transitions • $state – transition to another state, check what the current state is • $stateParams – get route and query parameter values for the current state
  • 9. Simple State Configuration angular.module('helloApp').config(function($stateProvider) { $stateProvider.state('login', { url: '/login', templateUrl: 'views/login.html' }) });
  • 10. Diff with ngRoute angular.module('helloApp').config(function($stateProvider) { $stateProvider.state('login', { url: '/login', templateUrl: 'views/login.html' }) }); angular.module('helloApp').config(function($routeProvider) { $routeProvider.when('/login', { templateUrl: 'views/login.html' }) });
  • 11. Nested State Configuration angular.module('helloApp').config(function ($stateProvider) { $stateProvider.state('app', { template: '<html><body><header>you fancy</header>' + '<ui-view></ui-view></body></html>' }).state('app.login', { url: '/login', templateUrl: 'views/login.html' }); });
  • 12. Transitioning States $state.go('login'); angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('acount', { url: '/account/:id?showDetails', templateUrl: 'views/account.html' }); }); $state.go('account', { id: 47, showDetails: true });
  • 13. In & Out Callbacks angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('app.acount', { url: '/account/:id', templateUrl: 'views/account.html', onEnter: function () { console.log('Google Analytics, open modal etc'); }, onExit: function () { console.log('clean up, animate etc'); } }); });
  • 14. UI-Router Directives • uiSref – declarative link to a state • uiSrefActive – adds CSS classes when a state is active • uiView – where to place the state template
  • 15. UI-Router Directives • uiSref is UI-Router’s ngHref angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('acount', { url: '/account/:id?showDetails', templateUrl: 'views/account.html' }); }); <a ui-sref="login">Login</a> <a ui-sref="account({ id: 47, showDetails: true })">Account</a>
  • 16. UI-Router Directives • uiView is UI-Router’s version of ngView • Tells UI-Router where to inject our views • Supports named views <html> <body> <header></header> <ui-view></ui-view> </body> </html>
  • 17. Named Views • More than one uiView in a template • Flexible and dynamic layouts <html> <body> <ui-view="header"></ui-view> <ui-view="sideNav"></ui-view> <ui-view="mainContent"></ui-view> </body> </html>
  • 18. Named Views angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('login', { url: '/login', views: { 'header': { templateUrl: 'views/unauth-header.html' }, 'sideNav': { templateUrl: 'views/unauth-sidenav.html' }, 'content': { templateUrl: 'views/login.html' } } }); });
  • 19. Resolve & Controllers angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('app.acount', { url: '/account/:id', templateUrl: 'views/account.html', resolve: { account: function ($http, $stateParams) { return $http.get('/api/account/' + $stateParams.id); } }, controller: function (account) { … } controller: 'AccountController' controller: ‘AccountController as account' }); });
  • 20. Nested Resolve & Controllers angular.module('sampleApp').config(function ($stateProvider) { $stateProvider.state('account', { url: '/account/:id', templateUrl: 'views/account.html', resolve: { account: function ($http, $stateParams) { … } } }) .state('account.details', { controller: function (account, DetailService) { … } }); });
  • 21. And more… • Regex parameters: url: “/contacts/{contactId:[0-9]{1,8}}" • $urlRouterProvider – watches $location and matches against URL configurations
  • 22. Resources • Egghead.io UI-Router Cheat sheet: http://goo.gl/ZcL0dv • UI-Router at CincyNG meetup: https://www.youtube.com/watch?v=lBqiZSemrqg • UI-Router extras: https://github.com/christopherthielen/ui-router-extras
  • 23. Didn't win? Get a HUGE discount on the course by visiting: http://tinyurl.com/AngularJSJumpstart