Skip to content

Instantly share code, notes, and snippets.

@suissa
Created September 28, 2016 03:34
Show Gist options
  • Save suissa/2bf52e255d9d9812408ac46b124d1ff5 to your computer and use it in GitHub Desktop.
Save suissa/2bf52e255d9d9812408ac46b124d1ff5 to your computer and use it in GitHub Desktop.
AngularJS $http Promise Chain
<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>
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