Created
November 5, 2010 00:47
-
-
Save vojtajina/663471 to your computer and use it in GitHub Desktop.
Angular - dynamic updating select
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 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