Download free for 30 days
Sign in
Upload
Language (EN)
Support
Business
Mobile
Social Media
Marketing
Technology
Art & Photos
Career
Design
Education
Presentations & Public Speaking
Government & Nonprofit
Healthcare
Internet
Law
Leadership & Management
Automotive
Engineering
Software
Recruiting & HR
Retail
Sales
Services
Science
Small Business & Entrepreneurship
Food
Environment
Economy & Finance
Data & Analytics
Investor Relations
Sports
Spiritual
News & Politics
Travel
Self Improvement
Real Estate
Entertainment & Humor
Health & Medicine
Devices & Hardware
Lifestyle
Change Language
Language
English
Español
Português
Français
Deutsche
Cancel
Save
Submit search
EN
Uploaded by
Rodrigo Branas
PDF, PPTX
3,252 views
HTTP Interceptors com AngularJS
Aprenda a utilizar HTTP Interceptors com AngularJS
Internet
◦
Read more
8
Save
Share
Embed
Embed presentation
Download
Download as PDF, PPTX
1
/ 28
2
/ 28
3
/ 28
4
/ 28
5
/ 28
6
/ 28
7
/ 28
8
/ 28
9
/ 28
10
/ 28
11
/ 28
12
/ 28
13
/ 28
14
/ 28
15
/ 28
16
/ 28
17
/ 28
18
/ 28
19
/ 28
20
/ 28
21
/ 28
22
/ 28
23
/ 28
24
/ 28
25
/ 28
26
/ 28
27
/ 28
28
/ 28
More Related Content
PPTX
Introdução ao AngularJS
by
Rodrigo Branas
PDF
IDT module 1.pdf
by
Raghavendra N
PDF
React Tech Salon
by
Chenguang ZHANG
PDF
Service Workers and APEX
by
Dimitri Gielis
PDF
Spring Data JPA + JSF + Maven + Mysql using Eclipse IDE
by
Nikhil Bhalwankar
PPTX
Headless CMS. Sitecore JSS getting started, tips and tricks
by
Artsem Prashkovich
PDF
What is Scrum? An Introduction to the Scrum Framework
by
Aggregage
PDF
SAFe for Teams Digital Workbook (5.0.1).pdf
by
ssuserac97f5
Introdução ao AngularJS
by
Rodrigo Branas
IDT module 1.pdf
by
Raghavendra N
React Tech Salon
by
Chenguang ZHANG
Service Workers and APEX
by
Dimitri Gielis
Spring Data JPA + JSF + Maven + Mysql using Eclipse IDE
by
Nikhil Bhalwankar
Headless CMS. Sitecore JSS getting started, tips and tricks
by
Artsem Prashkovich
What is Scrum? An Introduction to the Scrum Framework
by
Aggregage
SAFe for Teams Digital Workbook (5.0.1).pdf
by
ssuserac97f5
What's hot
PPTX
Its time to React.js
by
Ritesh Mehrotra
PDF
카카오는 애자일 한가요?
by
호정 이
PDF
從 DevOps 到 ChatOps:War Room、Bots 與 Automation
by
Chen Cheng-Wei
PDF
intro to DevOps
by
Mujahed Al-Tahle
PPTX
Design System Proposal
by
Charlie Weston
PDF
Angular Material (2) - NgVikingsConf
by
Tracy Lee
PPTX
Como uma dinâmica de Sprint Planning II pode ajudar o time
by
rafaelzampieri
PDF
Webpack DevTalk
by
Alessandro Bellini
PDF
DevOps: A Culture Transformation, More than Technology
by
CA Technologies
PDF
Design Pattern (Strategy & Template)
by
Alia Hamwi
PPTX
Information radiators
by
brendonpage
PDF
DevOps - A Gentle Introduction
by
Ganesh Samarthyam
PDF
Devops interview-questions-PDF
by
Mayank Kumar
Its time to React.js
by
Ritesh Mehrotra
카카오는 애자일 한가요?
by
호정 이
從 DevOps 到 ChatOps:War Room、Bots 與 Automation
by
Chen Cheng-Wei
intro to DevOps
by
Mujahed Al-Tahle
Design System Proposal
by
Charlie Weston
Angular Material (2) - NgVikingsConf
by
Tracy Lee
Como uma dinâmica de Sprint Planning II pode ajudar o time
by
rafaelzampieri
Webpack DevTalk
by
Alessandro Bellini
DevOps: A Culture Transformation, More than Technology
by
CA Technologies
Design Pattern (Strategy & Template)
by
Alia Hamwi
Information radiators
by
brendonpage
DevOps - A Gentle Introduction
by
Ganesh Samarthyam
Devops interview-questions-PDF
by
Mayank Kumar
Viewers also liked
PDF
Node.js - #7 - Core Modules - http - Parte 1 - Rodrigo Branas
by
Rodrigo Branas
PPTX
Criando serviços com AngularJS
by
Rodrigo Branas
PPTX
Utilizando diretivas com AngularJS
by
Rodrigo Branas
PPTX
Criando Filtros com AngularJS
by
Rodrigo Branas
PPTX
Scope AngularJS
by
Rodrigo Branas
PPTX
Criando aplicações Single-Page com AngularJS
by
Rodrigo Branas
PPTX
A evolução do AngularJS
by
Rodrigo Branas
PDF
#2 - Git - DAG
by
Rodrigo Branas
PPTX
AngularJS $http Interceptors (Explanation and Examples)
by
Brian Swartzfager
PDF
Node.js - #5 - Process - Rodrigo Branas
by
Rodrigo Branas
PDF
Node.js - #6 - Core Modules - net - Rodrigo Branas
by
Rodrigo Branas
PDF
Node.js - #2 - Sistema de Módulos - Rodrigo Branas
by
Rodrigo Branas
PPTX
HTTP, JSON, REST e AJAX com AngularJS
by
Rodrigo Branas
PPTX
JavaScript - Date
by
Rodrigo Branas
PPTX
Automação de Testes com AngularJS
by
Rodrigo Branas
PPTX
AngularJS - 10 passos para aprender a criar suas directivas
by
Janderson Fernandes Cardoso
PPTX
JavaScript - Expressões Regulares
by
Rodrigo Branas
PPTX
Minicurso - Desenvolvendo aplicações web com JavaScript e AngularJS - Estácio...
by
Rodrigo Branas
PPTX
Desvendando a linguagem JavaScript
by
Rodrigo Branas
PPTX
Grunt
by
Rodrigo Branas
Node.js - #7 - Core Modules - http - Parte 1 - Rodrigo Branas
by
Rodrigo Branas
Criando serviços com AngularJS
by
Rodrigo Branas
Utilizando diretivas com AngularJS
by
Rodrigo Branas
Criando Filtros com AngularJS
by
Rodrigo Branas
Scope AngularJS
by
Rodrigo Branas
Criando aplicações Single-Page com AngularJS
by
Rodrigo Branas
A evolução do AngularJS
by
Rodrigo Branas
#2 - Git - DAG
by
Rodrigo Branas
AngularJS $http Interceptors (Explanation and Examples)
by
Brian Swartzfager
Node.js - #5 - Process - Rodrigo Branas
by
Rodrigo Branas
Node.js - #6 - Core Modules - net - Rodrigo Branas
by
Rodrigo Branas
Node.js - #2 - Sistema de Módulos - Rodrigo Branas
by
Rodrigo Branas
HTTP, JSON, REST e AJAX com AngularJS
by
Rodrigo Branas
JavaScript - Date
by
Rodrigo Branas
Automação de Testes com AngularJS
by
Rodrigo Branas
AngularJS - 10 passos para aprender a criar suas directivas
by
Janderson Fernandes Cardoso
JavaScript - Expressões Regulares
by
Rodrigo Branas
Minicurso - Desenvolvendo aplicações web com JavaScript e AngularJS - Estácio...
by
Rodrigo Branas
Desvendando a linguagem JavaScript
by
Rodrigo Branas
Grunt
by
Rodrigo Branas
More from Rodrigo Branas
PDF
Clean Architecture
by
Rodrigo Branas
PDF
Node.js - #4 - Timers - Rodrigo Branas
by
Rodrigo Branas
PDF
Node.js - #3 - Global Objects - Rodrigo Branas
by
Rodrigo Branas
PDF
Node.js - #1 - Introdução - Rodrigo Branas
by
Rodrigo Branas
PDF
#6 - Git - Desfazendo as coisas
by
Rodrigo Branas
PDF
#1 - Git - Introdução
by
Rodrigo Branas
PDF
#5 - Git - Contribuindo com um repositório remoto
by
Rodrigo Branas
PDF
#4 - Git - Stash
by
Rodrigo Branas
PDF
#3 - Git - Branching e Merging
by
Rodrigo Branas
PPTX
Construindo Diretivas com AngularJS
by
Rodrigo Branas
PPTX
Técnicas de Refactoring
by
Rodrigo Branas
PPTX
Selenium - WebDriver
by
Rodrigo Branas
PPTX
Test-Driven Development com JavaScript, Jasmine Karma
by
Rodrigo Branas
PPTX
Bower
by
Rodrigo Branas
Clean Architecture
by
Rodrigo Branas
Node.js - #4 - Timers - Rodrigo Branas
by
Rodrigo Branas
Node.js - #3 - Global Objects - Rodrigo Branas
by
Rodrigo Branas
Node.js - #1 - Introdução - Rodrigo Branas
by
Rodrigo Branas
#6 - Git - Desfazendo as coisas
by
Rodrigo Branas
#1 - Git - Introdução
by
Rodrigo Branas
#5 - Git - Contribuindo com um repositório remoto
by
Rodrigo Branas
#4 - Git - Stash
by
Rodrigo Branas
#3 - Git - Branching e Merging
by
Rodrigo Branas
Construindo Diretivas com AngularJS
by
Rodrigo Branas
Técnicas de Refactoring
by
Rodrigo Branas
Selenium - WebDriver
by
Rodrigo Branas
Test-Driven Development com JavaScript, Jasmine Karma
by
Rodrigo Branas
Bower
by
Rodrigo Branas
HTTP Interceptors com AngularJS
1.
Rodrigo Branas –
@rodrigobranas - http://www.agilecode.com.br Interceptors com AngularJS
3.
Um interceptor é
um tipo de serviço que permite a interceptação das requisições e respostas do serviço $http.
4.
1. app.factory("nomeDoInterceptorA", function
($q) { 2. return { 3. request: function (config) { 4. return config; 5. }, 6. requestError: function (rejection) { 7. return $q.reject(rejection); 8. }, 9. response: function (response) { 10. return response; 11. }, 12. responseError: function (rejection) { 13. return $q.reject(rejection); 14. } 15. }; 16. });
5.
Configurando o interceptor O
serviço $http possui um array de interceptors que podem ser configurados na inicialização da aplicação.
6.
1. app.config(function ()
{ 2. });
7.
1. app.config(function ($httpProvider)
{ 2. });
8.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("nomeDoInterceptorA"); 3. });
9.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("nomeDoInterceptorA"); 3. $httpProvider.interceptors.push("nomeDoInterceptorB"); 4. });
10.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("nomeDoInterceptorA"); 3. $httpProvider.interceptors.push("nomeDoInterceptorB"); 4. $httpProvider.interceptors.push("nomeDoInterceptorC"); 5. });
11.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("nomeDoInterceptorA"); 3. $httpProvider.interceptors.push("nomeDoInterceptorB"); 4. $httpProvider.interceptors.push("nomeDoInterceptorC"); 5. });
12.
Timestamp Interceptor Adiciona
uma marcação contendo um timestamp em todas as requisições.
13.
1. app.factory("timestampInterceptor", function
() { 2. });
14.
1. app.factory("timestampInterceptor", function
() { 2. return { 3. }; 4. });
15.
1. app.factory("timestampInterceptor", function
() { 2. return { 3. request: function (config) { 4. return config; 5. } 6. }; 7. });
16.
1. app.factory("timestampInterceptor", function
() { 2. return { 3. request: function (config) { 4. var timestamp = new Date().getTime(); 5. config.url = config.url + "?timestamp=" + timestamp; 6. return config; 7. } 8. }; 9. });
17.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("timestampInterceptor"); 3. });
18.
Error Interceptor Exibe
a tela de erro padrão caso uma requisição HTTP receba um status code 404 como resposta.
19.
1. app.factory("errorInterceptor", function
() { 2. });
20.
1. app.factory("errorInterceptor", function
($q) { 2. return { 3. responseError: function (rejection) { 4. return $q.reject(rejection); 5. } 6. }; 7. });
21.
1. app.factory("errorInterceptor", function
($q, $location) { 2. return { 3. responseError: function (rejection) { 4. if (rejection.status == 404) { 5. $location.path("/error"); 6. } 7. return $q.reject(rejection); 8. } 9. }; 10. });
22.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("errorInterceptor"); 3. });
23.
Loading Interceptor Exibe
uma imagem de loading enquanto tiver uma requisição em andamento.
24.
1. app.factory("loadingInterceptor", function
() { 2. });
25.
1. app.factory("loadingInterceptor", function
($q) { 2. return { 3. request: function (config) { 4. return config; 5. }, 6. requestError: function (rejection) { 7. return $q.reject(rejection); 8. }, 9. response: function (response) { 10. return response; 11. }, 12. responseError: function (rejection) { 13. return $q.reject(rejection); 14. } 15. }; 16. });
26.
1. app.factory("loadingInterceptor", function
($q, $rootScope) { 2. return { 3. request: function (config) { 4. $rootScope.loading = true; 5. return config; 6. }, 7. requestError: function (rejection) { 8. $rootScope.loading = false; 9. return $q.reject(rejection); 10. }, 11. response: function (response) { 12. $rootScope.loading = false; 13. return response; 14. }, 15. responseError: function (rejection) { 16. $rootScope.loading = false; 17. return $q.reject(rejection); 18. } 19. }; 20. });
27.
1. app.config(function ($httpProvider)
{ 2. $httpProvider.interceptors.push("loadingInterceptor"); 3. });
28.
Rodrigo Branas Agile
Code: http://www.agilecode.com.br Twitter: @rodrigobranas SlideShare: http://www.slideshare.com/rodrigobranas YouTube: http://www.youtube.com/rodrigobranas LinkedIn: http://br.linkedin.com/in/rodrigobranas +Plus: https://plus.google.com/+RodrigoBranas GitHub: http://www.github.com/rodrigobranas
Editor's Notes
#3
Qual é a sua obra?
#4
Qual é a sua obra?
#5
Desmotivado
#6
Desmotivado
#7
Motivação
#8
Desmotivação
#9
Desmotivação
#10
Desmotivação
#11
Desmotivação
#12
Desmotivação
#13
Desmotivação
#14
Desmotivação
#15
Desmotivação
#16
Desmotivação
#17
Desmotivação
#18
Desmotivação
#19
Desmotivação
#20
Desmotivação
#21
Desmotivação
#22
Desmotivação
#23
Desmotivação
#24
Desmotivação
#25
Desmotivação
#26
Desmotivação
#27
Desmotivação
#28
Desmotivação
#29
Desmotivação
#30
Desmotivação
#31
Desmotivação
#32
Desmotivação
#33
Desmotivação
Download