Created
February 23, 2015 22:34
-
-
Save vic/6fbcfca5ea3a338e32a3 to your computer and use it in GitHub Desktop.
angular editable choices
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> | |
<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