Why does changing the value in a textarea break the binding?
Allow myVal
to update to say Hello
, but then if typing anything else, then clicking the button no longer updates the value.
html
<!doctype html>
<html ng-app="app">
<head>
</head>
<body>
<div ng-controller="Ctrl">
<textarea ng-bind="formModel.myVal"></textarea>
<button ng-click="update()">Update</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<script src="script.js"></script>
</body>
</html>
js
var app = angular.module('app', []);
app.controller('Ctrl', function($scope, $timeout) {
$scope.formModel = {};
$timeout(function() {
$scope.formModel.myVal = 'Hello';
}, 1000);
$scope.update = function() {
$scope.formModel.myVal = 'Bye';
};
});
Edit:
To clarify; I want one-way binding which is what ng-bind provides. I am wondering why changing the value in textarea breaks this one way binding. I would expect this if I had tried to bind directly to a string, but the binding is to an object property.