Skip to content

Instantly share code, notes, and snippets.

@MikeBild
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeBild/8db7431d3fe74784fb7d to your computer and use it in GitHub Desktop.
Save MikeBild/8db7431d3fe74784fb7d to your computer and use it in GitHub Desktop.
AngularJS tryGet(url)
<!doctype html>
<html data-ng-app="myApp">
<head>
<meta charset="utf-8">
<title>Try Get</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.0-beta.13/angular.min.js"></script>
</head>
<body data-ng-controller="demoCtrl">
<script>
angular
.module('myApp',[])
.controller('demoCtrl', function($http, $q){
$http.get('http://foobar1234.de')
.catch(function(data){
return $http.get('http://foobar1234.de');
})
.catch(function(){
return $http.get('http://www.google.de');
})
.catch(function(){
return $http.get('http://foobar1234.de');
})
.then(function(data){
console.log(data.status);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment