Sunday, 18 August 2013

Why doesn't an input field change update angular model?

Why doesn't an input field change update angular model?

This is a very newbie question but why doesn't
document.getElementById("demo").value
update angular model? It updates the input field, but it updates the model
only after manually putting something into the field.
Here's the code:
<div ng-controller="AddCtrl">
<input type="text" id="demo" ng-model="test.fld"
ng-change="change()"></input>
<br />
[ <a href="" onclick="somefnc()">pop</a> ]
[ <a href="" ng-click="add(test)">add</a> ]
<p>Test-field: {{test.fld}}</p>
</div>
<script>
function somefnc() {
document.getElementById("demo").value = "hi";
}
</script>
Here is also a Plunker

No comments:

Post a Comment