SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
Egor 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 Application
Dan Wahlin
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
RajthilakMCA
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
Brajesh Yadav
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJS
Loc Nguyen
 
Understanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeUnderstanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scope
Brajesh Yadav
 
Built in filters
Built in filtersBuilt in filters
Built in filters
Brajesh Yadav
 
J queryui
J queryuiJ queryui
J queryui
Inbal Geffen
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
Brajesh Yadav
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explained
Ramesh BN
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
Dzmitry Ivashutsin
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
aglemann
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JS
Alwyn Wymeersch
 
Directives
DirectivesDirectives
Directives
Brajesh Yadav
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
Damian Galarza
 
JQuery
JQueryJQuery
JQuery
Jussi Pohjolainen
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
Egor 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 Application
Dan Wahlin
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
RajthilakMCA
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
Brajesh Yadav
 
Up and Running with ReactJS
Up and Running with ReactJSUp and Running with ReactJS
Up and Running with ReactJS
Loc Nguyen
 
Understanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeUnderstanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scope
Brajesh Yadav
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
Brajesh Yadav
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explained
Ramesh BN
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
aglemann
 
CFUGbe talk about Angular JS
CFUGbe talk about Angular JSCFUGbe talk about Angular JS
CFUGbe talk about Angular JS
Alwyn 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 Modernizr
Jussi Pohjolainen
 

Viewers also liked (9)

Intro to UI-Router/TypeScript
Intro to UI-Router/TypeScriptIntro to UI-Router/TypeScript
Intro to UI-Router/TypeScript
Jamal Sinclair O'Garro
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
Alexe Bogdan
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
Sakthi Bro
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
John Staveley
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
Sergey Bolshchikov
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
Alexe Bogdan
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
Sakthi Bro
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
John Staveley
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Ad

Similar to 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
FalafelSoftware
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
Deepu 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
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
Riccardo Masetti
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
Loc Nguyen
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
Tamer Solieman
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
Betclic Everest Group Tech Team
 
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 Developers
Caldera Labs
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docs
Abhi166803
 
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
ExoLeaders.com
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
Filip Janevski
 
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
Matt 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 started
Stéphane Bégaudeau
 
Angularjs
AngularjsAngularjs
Angularjs
Ynon Perek
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
Dan 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 AngularJS
buttyx
 
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 js
codeandyou forums
 
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
FalafelSoftware
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
Deepu 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 Developers
Loc Nguyen
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
Tamer 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 Developers
Caldera Labs
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docs
Abhi166803
 
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
ExoLeaders.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 2015
Matt 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 started
Stéphane Bégaudeau
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
Dan 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 AngularJS
buttyx
 
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 js
codeandyou forums
 
Ad

Recently uploaded (20)

Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 

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