Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2015 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4fc9424750ce6a3b592c to your computer and use it in GitHub Desktop.
Save anonymous/4fc9424750ce6a3b592c to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/futehi
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="app">
<div ng-controller="SumController">
<select ng-model="value" ng-options="n for n in [1, 2, 3, 4, 5]"></select>
<button ng-click="add()">Add</button>
The sum of {{ values }} is {{ sum }}
</div>
<script id="jsbin-javascript">
angular
.module('app', [])
.controller('SumController', function($scope) {
$scope.values = [1, 2];
$scope.add = function() {
$scope.values.push(parseInt($scope.value));
};
$scope.$watch('values', function() {
$scope.sum = $scope.values.reduce(function(a, b) {
return a + b;
});
}, true);
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">angular
.module('app', [])
.controller('SumController', function($scope) {
$scope.values = [1, 2];
$scope.add = function() {
$scope.values.push(parseInt($scope.value));
};
$scope.$watch('values', function() {
$scope.sum = $scope.values.reduce(function(a, b) {
return a + b;
});
}, true);
});</script></body>
</html>
angular
.module('app', [])
.controller('SumController', function($scope) {
$scope.values = [1, 2];
$scope.add = function() {
$scope.values.push(parseInt($scope.value));
};
$scope.$watch('values', function() {
$scope.sum = $scope.values.reduce(function(a, b) {
return a + b;
});
}, true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment