Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created November 5, 2010 00:47
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 vojtajina/663471 to your computer and use it in GitHub Desktop.
Save vojtajina/663471 to your computer and use it in GitHub Desktop.
Angular - dynamic updating select
<!DOCTYPE HTML >
<html xmlns:ng="http://angularjs.org">
<head>
<script type="text/javascript" src="http://angularjs.org/ng/js/angular-debug.js" ng:autobind></script>
<script type="text/javascript">
function testController() {
// init the value
this.options = {1: 'one', 2: 'two'};
this.change = function() {
this.options = {10: 'ten', 20: 'twenty'};
this.$eval();
// fire the event by hand
var event = document.createEvent("HTMLEvents");
event.initEvent('change', true, true );
document.getElementById('my_select').dispatchEvent(event);
};
}
</script>
</head>
<body ng:controller="testController">
<select name="selectValue" id="my_select">
<option ng:repeat="opt in options">{{opt}}</option>
</select>
<br />
select value = {{selectValue}}<br />
<input type="button" ng:click="change()" value="TEST IT" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment