SecurKitty
SecurKitty

Reputation: 31

How to pass textarea content to angularjs function?

SO i am trying to pass what is written in the text area to a angularjs function

$scope.sendMessage = function(text, sender_user_id, receiver_group_id){
  $http({
      url: "http://www.adzone.io/tekst/send_message.php",
      method: "POST",
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      transformRequest: function(obj) {
          var str = [];
          for(var p in obj)
          str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
          return str.join("&");
      },
      data: {text: text, sender_user_id: sender_user_id, receiver_group_id: receiver_group_id}
  }).success(function(data, status, headers, config) {
      $scope.data = data;
  }).error(function(data, status, headers, config) {
      $scope.status = status;
  });
}



   <ons-list-item>
      <textarea id="myTextarea" class="textarea textarea--transparent" placeholder="Message" style="width: 100%; height: 100px;"></textarea>
    </ons-list-item>

      <div style="padding: 10px 9px" ng-controller="MasterController">
    <ons-button modifier="large" style="margin: 0 auto;" ng-click="sendMessage(x,40,55)">
      Send
    </ons-button>
  </div>

so for the "sendMessage(x,40,55)" I am passing only string, my question is how i can pass what is actually being writting in the textarea into "sendMessage("test",40,55)"?? thanks!

Upvotes: 0

Views: 1971

Answers (2)

Jbird
Jbird

Reputation: 2886

In your markup:

<textarea ng-model="textareaData"></textarea>

In your controller:

$scope.textareaData

Upvotes: 0

oseintow
oseintow

Reputation: 7371

set ng-model on your text area

<ons-list-item>
  <textarea id="myTextarea" ng-model="myText" class="textarea textarea--transparent" placeholder="Message" style="width: 100%; height: 100px;"></textarea>
</ons-list-item>

Then pass myText to sendMessage in the ng-click

<div style="padding: 10px 9px" ng-controller="MasterController">
    <ons-button modifier="large" style="margin: 0 auto;" ng-click="sendMessage(myText,40,55)">
     Send
    </ons-button>
</div>

Upvotes: 1

Related Questions