Updating with ng-model


#1

I’m having some problems updating a textarea from the controller.

In my view I have:

<label class="item item-input">
<textarea type="text" placeholder="Type your message" ng-model="message"></textarea>
</label>

Then in my controller I do:

$scope.sendMessage = function(msg) {
	       // code to send messages here works.
               // I want the below to clear the textarea, but it doesn't 
	       $scope.message = '';		
}

Any ideas what I am doing wrong?

UPDATE: I should mention that I am calling this function from a button ng-click and the send message part is working.


#2

Ok, I solved this. Although I know the how, not sure of the why.

I need to use dot notation to fix, so my input now becomes:

<label class="item item-input">
  <textarea type="text" placeholder="Type your message" ng-model="message.txt"></textarea>
</label>

then in my controller create the empty message object:

$scope.message = {};

and finally I can update my message textarea with:

$scope.message.txt = '';

Done!


#3

Thanks, very useful. It worked for me :wink: