0

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!

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I actually don't have 15 reputation yet! :( I am really sorry!
0

In your markup:

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

In your controller:

$scope.textareaData

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.