Skip to content

Instantly share code, notes, and snippets.

@pklink
Created March 18, 2015 22:23
Show Gist options
  • Save pklink/4f0539eba22f3cd2da75 to your computer and use it in GitHub Desktop.
Save pklink/4f0539eba22f3cd2da75 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/geqibu
<!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>
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