2016-07-24 6 views
0

をトリガではありません。最も重要な部分の1つは、白いカードの代わりに、提出するボタン付きのテキストボックスが1つあることです。私がsubmitを押すと、何も起こりません - Javascriptアラートは起動しません。AngularJSボタンクリックは、私はこれを変更しようとしている機能

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を使い慣れていないので、明らかなものがないかもしれません。どんな助けもありがとう!

+0

あなたはどこかに 'ng-controller'と' ng-app'を持っていると思いますよね?コントローラにブレークポイントを設定して、それがロード中であることを確認しましたか? –

+0

いいえ、そうでなければなりません。彼らはどこに行くのですか?愚かな質問を申し訳ありません。 – Stephen

+0

問題にjsfiddleやplunkerを提供してもらえますか? – varit05

答えて

2

問題がコントローラのselectSituationでの誤字です。今のところ$ scope.selectSituatonですが、$ scope.selectSituationになるはずです。

はコードの下で試してみてください。

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

私はそれはあなたの問題を解決すると信じています。

乾杯!

+1

ありがとう、私はそんなにばかだよ! – Stephen

関連する問題