gpt4 book ai didi

javascript - Angular Scope 在 onclick 函数中不起作用

转载 作者:行者123 更新时间:2023-12-02 16:05:21 26 4
gpt4 key购买 nike

我在这里遇到问题,正确的 $scope.testMessage 没有传递到 QB.chat.send...

现在,当在与 $scope.testMessage 绑定(bind)的输入字段中输入新信息时,会发生什么是对 HTML 中的 {{testMessage}} 的更新,这正是我们所期望的,但是当按下与 sendMessageClick( 绑定(bind)) 绑定(bind)的按钮时,会发生什么? ),这个新值不会传递到函数中——旧值(此处设置为“Cheese”)会传递到函数中。即使它已更改为“StinkingFrenchCheese”并且反射(reflect)在实时 HTML 的 {{testMessage}} 部分中。它仍然只将“Cheese”传递给 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 = "3354163-23837@chat.quickblox.com"; //countchew
var starshipenterprise = "3354099-23837@chat.quickblox.com"; //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) {

关于javascript - Angular Scope 在 onclick 函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30808539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com