AngularJS按钮点击不触发功能
AngularJS button click not triggering function
我正在尝试修改:https://github.com/amirrajan/nodejs-against-humanity
为了遵守我制定的游戏规则。最重要的部分之一是,应该有一个带有提交按钮的文本框,而不是白色卡片。当我按下submit时,什么都没有发生——Javascript警报不会触发或发生任何事情。
game.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>
services.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 });
}
};
});
controllers.js:
$scope.selectSituaton = function(textToAppend) {
alert('Situation fired');
GameService.selectSituaton($scope.gameId, $scope.playerId, textToAppend);
};
server.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的新手,所以我可能缺少一些显而易见的东西。感谢您的帮助!
问题是控制器中selectSituation的打字错误。目前,它是$scope。选择Situaton,而它应该是$scope。选择Sitation。
尝试使用以下代码:
$scope.selectSituation = function(textToAppend) {
alert('Situation fired');
GameService.selectSituaton($scope.gameId, $scope.playerId, textToAppend);
};
我相信它会解决你的问题。
干杯!
相关文章:
- 删除CKEditor工具栏按钮,但不删除功能
- 如何使用Java脚本创建提交按钮's的拖放功能
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- 第二次点击具有不同功能的按钮并更改文本
- 如果未按下该按钮,则在30秒内自动执行该功能
- 两个按钮在初次点击后会触发相同的功能
- 如何使用相同的按钮点击两个功能
- JavaScript表单提交没有't fire asp服务器端点击功能的提交按钮
- 自定义HTML5视频控件-退出按钮不会启动全屏切换功能
- 交互2个单选按钮2个不同的功能Javascript
- 美国地图插件,具有状态数据/悬停功能的新按钮
- Bootbox:取消对话框后的回调功能/点击'X'按钮
- on单击从按钮到功能
- 更改选择选项下拉列表与onclick功能按钮
- 功能按钮已禁用;从开始
- 运行功能按钮点击作为创建者用户-谷歌电子表格
- 基于单选按钮启用/禁用功能按钮
- 点击功能按钮更改画布
- 我可以重写或设置确认功能按钮吗? '文本
- 如何添加eventlistener上按钮点击,如果它已经有功能按钮点击