SlideShare a Scribd company logo
1 of 32
A represents a task that will finish in the future; 
A has three methods: 
then() 
catch() 
finally() 
A will be or
var a = 10; 
window.setTimeout(function(){ 
a += 10; 
}, 1000); 
console.log(a); // Will output 10;
setTimeout() / setInterval(); 
XmlHttpRequest; 
Element Creation; 
Web Workers; 
Generators;
* Immutable
Angular uses promises for everything that is async: 
$timeout; 
$http & response interceptors; 
$resource; 
$routeProvider.when(); 
much more.
Implemented using $q service 
function createPromise(resolve){ 
defered = $q.defer(); 
window.setTimeout(function(){ 
if (resolve) defered.resolve(10); 
else defered.reject("You provided a false value"); 
}, 1000); 
return defered.promise; 
} 
var promise = createPromise(true); 
promise.then(function(value){ 
console.log(value); 
}); 
console.log("The value will be shown after this.");
Result of 
var promise = createPromise(true); 
promise 
.then(function(value){ 
console.log(value) //10 
return value + 10; 
}, errorFn, notifyFn) 
.then(function(value){ 
console.log(value) //20 
return $q.reject(20); 
}, errorFn, notifyFn) 
.catch(errorFn) 
.finally(callbackFn);
ui-router
A within an app 
hierarchy 
Names are 
Navigate by 
views (ui-view) 
Populate 
populates 'parts' 
A within your app 
hierarchy 
Names are 
Navigate by 
view (ng-view) 
Populate 
populate 
'parts'
<body> 
<ul> 
<li><a ui-sref="home">Home</a></li> 
<li><a ui-sref="about">About</a></li> 
</ul> 
<section ui-view></section> 
</body> 
angular 
.module("myApp", []) 
.config(['$stateProvider', function($stateProvider){ 
$stateProvider 
.state('home', { 
template: '<h1>Home</h1>' 
}) 
.state('about', { 
template: '<h1>About</h1>' 
}); 
}])
$stateProvider 
.state('stateName', { 
template: 'String Html content', 
templateUrl: 'String URL', 
templateProvider: function(){}, // Function, must return HTML String 
controller: 'Function or name as String' 
controllerProvider: function(){}, // Function, must return controller function or name as String 
resolve: {} // A map of dependencies wich shoul be resolved and injected into controller 
url: 'A url with optional params', 
params: [], //Array of parameter names or regular expressions 
views: { 
//Object to define multiple views 
'nameOfView': { 
template: '', 
controller: '' 
} 
}, 
abstract: true //An abstract state will never be directly activated, but can provide inherited data: {}, 
onEnter: function(){}, 
onExit: function(){}, 
reloadOnSearch: true 
})
The resolve property is a map object: 
: name of the dependency 
: 
: alias for a service 
: 
Return value is treated as the dependency. 
If the result is a promise, it's resolved before 
the controller is instatiated.
$stateProvider 
.state('stateName', { 
resolve:{ 
simpleObj: function() { 
return {value: 'some string'} 
}, 
promiseObj: ['$http', function($http) { 
//$http returns a promise 
return $http({method: 'GET', url: '/someUrl'}); 
}] 
}, 
controller: ['$scope', 'simpleObj', 'promiseObj', function($scope, simpleObj, promiseObj){ 
$scope.simple = simpleObj.value; 
// You can be sure that promiseObj is ready to use! 
$scope.items = promiseObj.items; 
$scope.items = promiseObj2.items; 
}] 
})
There are three main ways to activate a state: 
1. Call $state.go(); 
2. Click a link containing the ui-sref directive; 
3. Navigate to the url associated with the state.
myApp.controller('contactCtrl', ['$scope', '$state', 
function($scope, $state){ 
$scope.goToDetails = function(){ 
$state.go('contact.details', {id: selectedId}); 
} 
} 
Params: 
1. state name 
2. state params ( ) 
3. options ( )
You can navigate relative to current state 
by using special characters: 
1. is up; 
2. is down.
Go to sibling - $state.go('^.1')
Generate anchors for state references 
<a ui-sref="contacts.detail({ id: 3 })"></a> 
<!-- Can Generate --> 
<a ui-sref="contacts.detail({ id: 3 })" href="#/contacts/3"></a> 
Can use relative paths and can have options 
<a ui-sref="^" ui-sref-opts="{location : false}">Go up</a>
$stateProvider 
.state("home", { ... }); 
.state("contacts", { ... }); 
.state("contacts.detail", { ... }); 
.state("contacts.detail.edit", { ... }); 
The dot in the state names auto-denotes parental 
hierarchy. 
It knows that is a of .
<!-- index.html --> 
<body> 
<div ui-view></div> 
</body> 
<!-- page.html --> 
<h1>My Contacts</h1> 
<div ui-view></div> 
<!-- page.list.html --> 
<ul> 
<li ng-repeat="item in list"> 
<a>{{item.name}}</a> 
</li> 
</ul> 
angular 
.module('myapp', ["ui.router"]) 
.config(function($stateProvider, $urlRouterProvider 
$urlRouterProvider.otherwise("/list") 
$stateProvider 
.state('page', { 
abstract: true, 
templateUrl: 'page.html', 
resolve: { 
list: function($http){ 
return $http({method: 'GET', url: '/someUrl' 
} 
} 
}) 
.state('page.list', { 
url: '/list', 
controller: function($scope, list){ 
$scope.list= list; 
} 
templateUrl: 'page.list.html' 
}); 
});
Scope inherits from parent 
properties 
methods 
Child states inherit from their parents: 
resolved dependencies 
custom data
.state('parent', { 
resolve:{ 
resA: function(){ 
return {'value': 'A'}; 
} 
}, 
controller: function($scope, resA){ 
$scope.resA = resA.value; 
} 
}) 
.state('parent.child', { 
resolve:{ 
resB: function(resA){ 
return {'value': resA.value + 'B'}; 
} 
}, 
controller: function($scope, resA, resB){ 
$scope.resA2 = resA.value; 
$scope.resB = resB.value; 
}
<body> 
<div ui-view="filters"></div> 
<div ui-view="tabledata"></div> 
<div ui-view="graph"></div> 
</body> 
$stateProvider 
.state('report',{ 
url: '', 
resolve: {}, 
views: { 
'filters': { 
templateUrl: 'report-filters.html', 
controller: function($scope){} 
}, 
'tabledata': { 
templateUrl: 'report-table.html', 
controller: function($scope){} 
}, 
'graph': { 
templateUrl: 'report-graph.html', 
controller: function($scope){} 
}, 
} 
})
Can use relative or absolute naming 
(always parent) 
filters - 'filters' view in parent template 
- unnamed view in parent template 
(uses @ symbol) 
- 'filters' view in 'report' state's template 
- 'filters' view in index.html. 
- unnamed view in 'report' state's template
$stateProvider 
.state('page', { 
url: "/page", 
templateUrl: 'page.html' 
}) 
.state('page.item', { 
url: "/{id}?filter&anotherParam", 
templateUrl: 'page-item.html', 
controller: function ($stateParams) { 
console.log($stateParams.id) 
} 
}) 
.state('page.item.details', { 
url: "/details", 
templateUrl: 'page-item-details.html', 
}) 
page.item's url becomes: 
page.item.details url becomes:
Plunker link
Angular API Reference 
Tim Kindberg slides 
uiRouter guide

More Related Content

What's hot

What's hot (20)

Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
Introducing AngularJS
Introducing AngularJSIntroducing AngularJS
Introducing AngularJS
 
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
 
Ui router
Ui routerUi router
Ui router
 
AngularJS $Provide Service
AngularJS $Provide ServiceAngularJS $Provide Service
AngularJS $Provide Service
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 

Viewers also liked

Viewers also liked (18)

AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Intro to UI-Router/TypeScript
Intro to UI-Router/TypeScriptIntro to UI-Router/TypeScript
Intro to UI-Router/TypeScript
 
Architecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouterArchitecture, Auth, and Routing with uiRouter
Architecture, Auth, and Routing with uiRouter
 
Refactoring
RefactoringRefactoring
Refactoring
 
Refactoring Golf
Refactoring GolfRefactoring Golf
Refactoring Golf
 
Angular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesAngular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of States
 
Basics of angular directive (Part - 1)
Basics of angular directive (Part - 1)Basics of angular directive (Part - 1)
Basics of angular directive (Part - 1)
 
Redux in Angular2 for jsbe
Redux in Angular2 for jsbeRedux in Angular2 for jsbe
Redux in Angular2 for jsbe
 
AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directives
 
AngularJS custom directive
AngularJS custom directiveAngularJS custom directive
AngularJS custom directive
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom Directives
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and running
 
Angular redux
Angular reduxAngular redux
Angular redux
 
Functional Reactive Angular 2
Functional Reactive Angular 2 Functional Reactive Angular 2
Functional Reactive Angular 2
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 

Similar to Angular Promises and Advanced Routing

Similar to Angular Promises and Advanced Routing (20)

Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Angular Tutorial Freshers and Experienced
Angular Tutorial Freshers and ExperiencedAngular Tutorial Freshers and Experienced
Angular Tutorial Freshers and Experienced
 
Data20161007
Data20161007Data20161007
Data20161007
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
React 101
React 101React 101
React 101
 
Cakephp2study tips集
Cakephp2study tips集Cakephp2study tips集
Cakephp2study tips集
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
node.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ionode.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.io
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Building evented single page applications
Building evented single page applicationsBuilding evented single page applications
Building evented single page applications
 
Building Evented Single Page Applications
Building Evented Single Page ApplicationsBuilding Evented Single Page Applications
Building Evented Single Page Applications
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integração
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 

More from Alexe Bogdan (7)

Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
HTML & JavaScript Introduction
HTML & JavaScript IntroductionHTML & JavaScript Introduction
HTML & JavaScript Introduction
 
Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directives
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
 
AngularJS - dependency injection
AngularJS - dependency injectionAngularJS - dependency injection
AngularJS - dependency injection
 
AngularJS - introduction & how it works?
AngularJS - introduction & how it works?AngularJS - introduction & how it works?
AngularJS - introduction & how it works?
 

Recently uploaded

Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ellan12
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 

Recently uploaded (20)

Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 

Angular Promises and Advanced Routing

  • 1.
  • 2.
  • 3. A represents a task that will finish in the future; A has three methods: then() catch() finally() A will be or
  • 4. var a = 10; window.setTimeout(function(){ a += 10; }, 1000); console.log(a); // Will output 10;
  • 5. setTimeout() / setInterval(); XmlHttpRequest; Element Creation; Web Workers; Generators;
  • 7.
  • 8. Angular uses promises for everything that is async: $timeout; $http & response interceptors; $resource; $routeProvider.when(); much more.
  • 9. Implemented using $q service function createPromise(resolve){ defered = $q.defer(); window.setTimeout(function(){ if (resolve) defered.resolve(10); else defered.reject("You provided a false value"); }, 1000); return defered.promise; } var promise = createPromise(true); promise.then(function(value){ console.log(value); }); console.log("The value will be shown after this.");
  • 10. Result of var promise = createPromise(true); promise .then(function(value){ console.log(value) //10 return value + 10; }, errorFn, notifyFn) .then(function(value){ console.log(value) //20 return $q.reject(20); }, errorFn, notifyFn) .catch(errorFn) .finally(callbackFn);
  • 12.
  • 13.
  • 14. A within an app hierarchy Names are Navigate by views (ui-view) Populate populates 'parts' A within your app hierarchy Names are Navigate by view (ng-view) Populate populate 'parts'
  • 15. <body> <ul> <li><a ui-sref="home">Home</a></li> <li><a ui-sref="about">About</a></li> </ul> <section ui-view></section> </body> angular .module("myApp", []) .config(['$stateProvider', function($stateProvider){ $stateProvider .state('home', { template: '<h1>Home</h1>' }) .state('about', { template: '<h1>About</h1>' }); }])
  • 16. $stateProvider .state('stateName', { template: 'String Html content', templateUrl: 'String URL', templateProvider: function(){}, // Function, must return HTML String controller: 'Function or name as String' controllerProvider: function(){}, // Function, must return controller function or name as String resolve: {} // A map of dependencies wich shoul be resolved and injected into controller url: 'A url with optional params', params: [], //Array of parameter names or regular expressions views: { //Object to define multiple views 'nameOfView': { template: '', controller: '' } }, abstract: true //An abstract state will never be directly activated, but can provide inherited data: {}, onEnter: function(){}, onExit: function(){}, reloadOnSearch: true })
  • 17. The resolve property is a map object: : name of the dependency : : alias for a service : Return value is treated as the dependency. If the result is a promise, it's resolved before the controller is instatiated.
  • 18. $stateProvider .state('stateName', { resolve:{ simpleObj: function() { return {value: 'some string'} }, promiseObj: ['$http', function($http) { //$http returns a promise return $http({method: 'GET', url: '/someUrl'}); }] }, controller: ['$scope', 'simpleObj', 'promiseObj', function($scope, simpleObj, promiseObj){ $scope.simple = simpleObj.value; // You can be sure that promiseObj is ready to use! $scope.items = promiseObj.items; $scope.items = promiseObj2.items; }] })
  • 19. There are three main ways to activate a state: 1. Call $state.go(); 2. Click a link containing the ui-sref directive; 3. Navigate to the url associated with the state.
  • 20. myApp.controller('contactCtrl', ['$scope', '$state', function($scope, $state){ $scope.goToDetails = function(){ $state.go('contact.details', {id: selectedId}); } } Params: 1. state name 2. state params ( ) 3. options ( )
  • 21. You can navigate relative to current state by using special characters: 1. is up; 2. is down.
  • 22. Go to sibling - $state.go('^.1')
  • 23. Generate anchors for state references <a ui-sref="contacts.detail({ id: 3 })"></a> <!-- Can Generate --> <a ui-sref="contacts.detail({ id: 3 })" href="#/contacts/3"></a> Can use relative paths and can have options <a ui-sref="^" ui-sref-opts="{location : false}">Go up</a>
  • 24. $stateProvider .state("home", { ... }); .state("contacts", { ... }); .state("contacts.detail", { ... }); .state("contacts.detail.edit", { ... }); The dot in the state names auto-denotes parental hierarchy. It knows that is a of .
  • 25. <!-- index.html --> <body> <div ui-view></div> </body> <!-- page.html --> <h1>My Contacts</h1> <div ui-view></div> <!-- page.list.html --> <ul> <li ng-repeat="item in list"> <a>{{item.name}}</a> </li> </ul> angular .module('myapp', ["ui.router"]) .config(function($stateProvider, $urlRouterProvider $urlRouterProvider.otherwise("/list") $stateProvider .state('page', { abstract: true, templateUrl: 'page.html', resolve: { list: function($http){ return $http({method: 'GET', url: '/someUrl' } } }) .state('page.list', { url: '/list', controller: function($scope, list){ $scope.list= list; } templateUrl: 'page.list.html' }); });
  • 26. Scope inherits from parent properties methods Child states inherit from their parents: resolved dependencies custom data
  • 27. .state('parent', { resolve:{ resA: function(){ return {'value': 'A'}; } }, controller: function($scope, resA){ $scope.resA = resA.value; } }) .state('parent.child', { resolve:{ resB: function(resA){ return {'value': resA.value + 'B'}; } }, controller: function($scope, resA, resB){ $scope.resA2 = resA.value; $scope.resB = resB.value; }
  • 28. <body> <div ui-view="filters"></div> <div ui-view="tabledata"></div> <div ui-view="graph"></div> </body> $stateProvider .state('report',{ url: '', resolve: {}, views: { 'filters': { templateUrl: 'report-filters.html', controller: function($scope){} }, 'tabledata': { templateUrl: 'report-table.html', controller: function($scope){} }, 'graph': { templateUrl: 'report-graph.html', controller: function($scope){} }, } })
  • 29. Can use relative or absolute naming (always parent) filters - 'filters' view in parent template - unnamed view in parent template (uses @ symbol) - 'filters' view in 'report' state's template - 'filters' view in index.html. - unnamed view in 'report' state's template
  • 30. $stateProvider .state('page', { url: "/page", templateUrl: 'page.html' }) .state('page.item', { url: "/{id}?filter&anotherParam", templateUrl: 'page-item.html', controller: function ($stateParams) { console.log($stateParams.id) } }) .state('page.item.details', { url: "/details", templateUrl: 'page-item-details.html', }) page.item's url becomes: page.item.details url becomes:
  • 32. Angular API Reference Tim Kindberg slides uiRouter guide