gpt4 book ai didi

javascript - AngularJS按钮点击不触发功能

转载 作者:行者123 更新时间:2023-12-02 14:22:24 25 4
gpt4 key购买 nike

我正在尝试修改此:https://github.com/amirrajan/nodejs-against-humanity

按照我制定的游戏规则进行工作。最重要的部分之一是,应该有一个带有提交按钮的文本框,而不是白卡。当我按下提交时,没有任何反应 - Javascript 警报不会触发或发生任何事情。

游戏.html:

<div class="row" ng-show="showWhiteCardList()">
<table id="whiteCards" class="table">
<tbody id="whiteCardSelection">
<tr>
<td>
<textarea ng-model="situationAppendage"></textarea>
<button class="btn btn-default" ng-click="selectSituation(situationAppendage)">Submit</button>
</td>
</tr>
</tbody>
</table>
</div>

服务.js:

angular.module('myApp.services', [])
.factory('GameService', function($http) {
var s4 = function() {
return Math.floor(Math.random() * 0x10000).toString();
};
var guid = function(){
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
};
var pId = guid();

return {
playerName: '',
playerId : pId,
newGameId : guid(),
currentGameId: undefined,
initName: function() {
if(this.playerName.length === 0) {
this.playerName = 'anonymous ' + s4();
}
},
getGames: function() {
return $http.get('/list');
},
createGame: function() {
return $http.post('/add', { id: guid(), name: this.playerName + "'s game" });
},
joinGame: function(gameId, playerId, name) {
return $http.post("/joingame", { gameId: gameId, playerId: playerId, playerName: name });
},
departGame: function(gameId, playerId) {
$http.post('/departgame', { gameId: gameId, playerId: playerId});
},
selectCard: function(gameId, playerId, selectedCard){
$http.post("/selectCard", { gameId: gameId, playerId: playerId, whiteCardId: selectedCard });
},
selectSituation: function(gameId, playerId, textBoxText){
$http.post("/selectSituation", { gameId: gameId, playerId: playerId, textBoxText : textBoxText });
},
selectWinner: function(gameId, selectedCard) {
$http.post("/selectWinner", { gameId: gameId, cardId: selectedCard });
},
readyForNextRound: function(gameId, playerId) {
$http.post("readyForNextRound", { playerId: playerId, gameId: gameId });
}
};
});

Controller .js:

$scope.selectSituaton = function(textToAppend) {
alert('Situation fired');
GameService.selectSituaton($scope.gameId, $scope.playerId, textToAppend);
};

服务器.js:

app.post('/selectSituation', function(req, res) {
console.log("Triggered");
Game.selectSituation(req.body.gameId, req.body.playerId, req.body.textBoxText);
broadcastGame(req.body.gameId);
returnGame(req.body.gameId, res);
});

我是 Node.JS、AngularJS 和 Javascript 的新手,所以我可能遗漏了一些明显的东西。如有任何帮助,我们将不胜感激!

最佳答案

问题是 Controller 中 selectSituation 的拼写错误。目前它是 $scope.selectSituaton,而它应该是 $scope.selectSituation

尝试使用以下代码:

$scope.selectSituation = function(textToAppend) {
alert('Situation fired');
GameService.selectSituaton($scope.gameId, $scope.playerId, textToAppend);
};

我相信它会解决您的问题。

干杯!

关于javascript - AngularJS按钮点击不触发功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38548321/

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