我在这里遇到问题,其中正确的$ scope.testMessage没有传递到QB.chat.send中。
现在,在与$ scope.testMessage关联的输入字段中输入新信息时会发生什么,这是对HTML中{{testMessage}}的更新,这是我们所期望的,但是当按下与sendMessageClick()关联的按钮时,新值不会传递到函数中,而是将旧值(此处设置为“ Cheese”)传递给该函数。即使已将其更改为“ StinkingFrenchCheese”,这也反映在实时HTML的{{testMessage}}部分中。它仍然仅将“奶酪”传递给sendMessageClick。
$scope.testMessage = "Cheese";
console.log($scope.testMessage);
$scope.sendMessageClick = function() {
console.log("message = " + $scope.testMessage);
var user = $rootScope.user;
console.log('sendMessageclick');
var countchew = "[email protected]"; //countchew
var starshipenterprise = "[email protected]"; //starshipenterprise
if (user == "countchew"){
QB.chat.roster.confirm(starshipenterprise, function(){
console.log("roster.confirm called");
});
QB.chat.roster.add(starshipenterprise, function() {
console.log("roster.add called");
});
var chewparams = {type: 'chat', name: 'testMessage', body: ($scope.testMessage), extension: {save_to_history: 1}};
QB.chat.send(starshipenterprise, chewparams);
} else if (user == "starshipenterprise"){
QB.chat.roster.confirm(countchew, function() {
console.log("roster.confirm called");
});
QB.chat.roster.add(countchew, function() {
console.log("roster.add called");
});
var starparams = {type: 'chat', name: 'testMessage', body: ($scope.testMessage), extension: {save_to_history: 1}};
QB.chat.send(countchew, starparams);
}
};
<ion-view view-title="Chat">
<ion-content>
<center class="padding-vertical">Chat 'em up</center>
<!-- Begin Login Form -->
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="User Name" ng-model="user.username">
</label>
<label class="item item-input">
<input type="text" placeholder="Password" ng-model="user.password">
</label>
<button class="button button-full button-balanced" data-ng-click="signInClick()">
Sign In
</button>
<label class="item item-input">
<input type="text" placeholder="Input your message!" ng-model="inputMessage">
</label>
<button class="button button-full button-balanced" data-ng-click="sendMessageClick()">
Send your message
</button>
<button class="button button-full button-balanced" data-ng-click="getCurrentParseUser()">
Get Current Parse User
</button>
<button class="button button-full button-balanced" data-ng-click="QBDisconnect()">
Disconnect from QB chat
</button>
<p>The message is : {{testMessage}}</p>
<p>Debug area says : {{debug}}</p>
<label class="item item-input">
<input type="text" placeholder="Give some text!" ng-model="testMessage">
</label>
<button class="button button-full button-balanced" data-ng-click="sendMessageClick()">
Send your message
</button>
</div>
<!-- End Login Form -->
</ion-content>
</ion-view>
最佳答案
尝试将消息传递给点击处理程序:
<button class="button button-full button-balanced" data-ng-click="sendMessageClick(testMessage)">
然后让您的onclick处理程序接收新消息作为输入
$scope.sendMessageClick = function(msg) {