A Pen by Jean Carlo Nascimento on CodePen.
Created
September 28, 2016 03:34
-
-
Save suissa/2bf52e255d9d9812408ac46b124d1ff5 to your computer and use it in GitHub Desktop.
AngularJS $http Promise Chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html ng-app="myApp"> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" /> | |
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> | |
<script src="http://code.angularjs.org/1.2.8/angular-sanitize.js"></script> | |
<meta charset=utf-8 /> | |
<title>$http's Promise Chain</title> | |
</head> | |
<body> | |
<div class="container" ng-controller="MainCtrl"> | |
1:<pre>{{part1|json}}</pre> | |
<br><br> | |
2:<pre>{{part2|json}}</pre> | |
<br><br> | |
3:<pre>{{part3|json}}</pre> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', []).controller('MainCtrl', function($scope, $http) { | |
$http.get('https://crossorigin.me/http://labs.edysegura.com/busca-por-cep/cep/endereco.php?cep=06608430') | |
.then(function(json) { | |
console.log('1', json) | |
$scope.part1 = json.data; | |
return $http.get('https://crossorigin.me/http://labs.edysegura.com/busca-por-cep/cep/endereco.php?cep=80215223'); | |
}) | |
.then(function(json) { | |
console.log('2', json) | |
$scope.part2 = json.data; | |
return $http.get('https://crossorigin.me/http://labs.edysegura.com/busca-por-cep/cep/endereco.php?cep=83605490'); | |
}) | |
.then(function(json) { | |
console.log('3', json) | |
$scope.part3 = json.data; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment