Skip to content

Instantly share code, notes, and snippets.

@vic
Created February 23, 2015 22:34
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 vic/6fbcfca5ea3a338e32a3 to your computer and use it in GitHub Desktop.
Save vic/6fbcfca5ea3a338e32a3 to your computer and use it in GitHub Desktop.
angular editable choices
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script>
var foo = {
choices: ['uno', 'dos']
};
Foo.$inject = ['$scope'];
function Foo ($scope) {
$scope.foo = foo;
$scope.add = function () {
console.log($scope.foo);
$scope.foo.choices.push("Opcion "+$scope.foo.choices.length);
}
$scope.set = function (idx, val) {
$scope.foo.choices[idx] = val;
}
}
angular.
module('foo', []).
controller('FooCtrl', Foo);
</script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="foo">
<div ng-controller="FooCtrl">
<pre>{{ foo | json }}</pre>
<select ng-options="c for c in foo.choices" ng-model="val">
</select>
<div ng-repeat="c in foo.choices">
<input type="text" ng-model="c" ng-blur="set($index, c)" />
</div>
<input type="button" ng-click="add()" value="Add option"/>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment