所以我试图将文本区域中写入的内容传递给angularjs函数
$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>
所以对于“sendMessage(x,40,55)”我只传递字符串,我的问题是如何将textarea中实际写入的内容传递给“sendMessage(”test“,40,55)” ?? 谢谢!
答案 0 :(得分:0)
在文本区域设置ng-model
<ons-list-item>
<textarea id="myTextarea" ng-model="myText" class="textarea textarea--transparent" placeholder="Message" style="width: 100%; height: 100px;"></textarea>
</ons-list-item>
然后在ng-click
中将myText传递给sendMessage<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>
答案 1 :(得分:0)
在你的标记中:
<textarea ng-model="textareaData"></textarea>
在您的控制器中:
$scope.textareaData