I have a simple modal which contains a text area. My problem is resetting the data of the textarea.
Here is my modal:
<div class="modal fade" ng-controller="MyCtrl">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<textarea ng-model="content" ng-change="statusChange(content)" placeholder="update" required="required"></textarea>
</div>
</div>
<div class="modal-footer">
<a class="btn" data-dismiss="modal" aria-hidden="true" ng-click="reset()">
Cancel
</a>
</div>
</div>
</div>
My controller:
myApp.controller('MyCtrl', function($scope){
$scope.content="";
$scope.statusChange = function(param){
$scope.content = param;
}
$scope.reset = function(){
$scope.content = "";
}
})
My problem: I have the data in the textarea bound to content via ng-model, but if I enter content into my text area, and then close the modal, we get $scope.content=""
, however, when I reopen the modal, the textarea still contains the previously entered data. I can confirm by printing out the data of the content, that the data in the text area is not the same as the value of $scope.content
.
How can I force the text area to have the same value of $scope.content
when the modal is reopened?
Here is a JSFiddle of the problem http://jsfiddle.net/RLQhh/64/. To see the issue, open the modal, type something in the textarea and then click the close button. Notice the console output (it should show what you typed, followed by the empty string). Now reopen the modal, and you will see that the last thing you typed is what is in the textarea. Also notice then reopening the window, the current data in $scope.content
is displayed in the console (it is empty).