Created
March 18, 2015 22:23
-
-
Save pklink/4f0539eba22f3cd2da75 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/geqibu
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 ng-app="myApp"> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="myController"> | |
<p>Output 1: <span ng-bind="output1"></span></p> | |
<button type="button" ng-click="roll()">roll!</button> | |
<br /> | |
<input type="text" ng-model="log" disabled> | |
<script id="jsbin-javascript"> | |
var app; | |
app = angular.module('myApp', []); | |
app.controller('myController', function($scope, $q) { | |
var tryIt; | |
$scope.output1 = null; | |
tryIt = function() { | |
var deferred, rnd; | |
deferred = $q.defer(); | |
rnd = Math.random(); | |
if (rnd > 0.5) { | |
deferred.resolve(rnd); | |
} else { | |
deferred.reject(rnd); | |
} | |
return deferred.promise; | |
}; | |
return $scope.roll = function() { | |
tryIt().then(function(result) { | |
$scope.output1 = ':-)'; | |
return $scope.log = result; | |
}, function(result) { | |
$scope.output1 = ':-('; | |
return $scope.log = result; | |
}); | |
}; | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="myController"> | |
<p>Output 1: <span ng-bind="output1"></span></p> | |
<button type="button" ng-click="roll()">roll!</button> | |
<br /> | |
<input type="text" ng-model="log" disabled> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">app = angular.module('myApp', []) | |
app.controller('myController', ($scope, $q) -> | |
$scope.output1 = null | |
tryIt = -> | |
deferred = $q.defer() | |
rnd = Math.random() | |
if (rnd > 0.5) | |
deferred.resolve(rnd) | |
else | |
deferred.reject(rnd) | |
deferred.promise | |
$scope.roll = -> | |
tryIt().then( | |
(result) -> | |
$scope.output1 = ':-)' | |
$scope.log = result | |
(result) -> | |
$scope.output1 = ':-(' | |
$scope.log = result | |
) | |
return | |
)</script></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
var app; | |
app = angular.module('myApp', []); | |
app.controller('myController', function($scope, $q) { | |
var tryIt; | |
$scope.output1 = null; | |
tryIt = function() { | |
var deferred, rnd; | |
deferred = $q.defer(); | |
rnd = Math.random(); | |
if (rnd > 0.5) { | |
deferred.resolve(rnd); | |
} else { | |
deferred.reject(rnd); | |
} | |
return deferred.promise; | |
}; | |
return $scope.roll = function() { | |
tryIt().then(function(result) { | |
$scope.output1 = ':-)'; | |
return $scope.log = result; | |
}, function(result) { | |
$scope.output1 = ':-('; | |
return $scope.log = result; | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment