Reputation: 1526
I am using AngularJS for a simple SPA.
This application includes a <textarea>
which shows, by default a value from a binding:
<textarea>{{activeField.rawContent}}</textarea>
One should be able to edit content in this textarea, then save it to a database.
My problem is, as soon as an input was made, the textarea will save this input and afterwards no more show the content of the binding, even when activeField.rawContent
is updated.
How could i prevent this behaviour?
Upvotes: 1
Views: 613
Reputation: 48972
The {{}}
is actually ng-Bind
behind the scenes which is one-way data binding.
ng-model
is two-way data binding.
In your code, what you actually do is inserting text content, not bind the data. It's recommended in angular documentation to use ng-model in this case. Try changing it to:
<textarea ng-model="activeField.rawContent"></textarea>
For more information, check this thread, ng-model, ng-bind
Upvotes: 2
Reputation: 11391
When binding editable data to input/textarea fields you need to use the ng-model directive. This hooks into the elements change events and propagates the changes back to the model.
In this case you would implement this with:
<textarea ng-model="activeField.rawContent"></textarea>
Upvotes: 1