Created
May 13, 2014 13:56
-
-
Save aBuder/58ab2d2ec158f2b59509 to your computer and use it in GitHub Desktop.
AngularJs Promise
This file contains 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
<!DOCTYPE html> | |
<html lang="en" ng-app > | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script> | |
</head> | |
<body ng-controller="MainController"> | |
<label>Bitte gib Deinen Namen ein:</label> | |
<input type="text" ng-model="name"> | |
<hr> | |
<strong>Hallo {{name}}!</strong> | |
</body> | |
</html> |
This file contains 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
function MainController ( $scope, $q){ | |
getName().then( | |
function( response ){ | |
console.log("onSuccess:" +response); | |
}, | |
function( error ){ | |
console.log( "onError:" +error); | |
} | |
); | |
function getName(){ | |
var deferred = $q.defer(); | |
var check = true; | |
if(false){ | |
setTimeout(function(){ | |
deferred.resolve("Cool Man after 5 sek "); | |
}, 5000); | |
}else{ | |
setTimeout(function(){ | |
deferred.reject("Cool Man after 10 sek "); | |
}, 10000); | |
} | |
return deferred.promise; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment