0

I am trying to modify this: https://github.com/amirrajan/nodejs-against-humanity

To work with the rules of a game I made up. One of the most significant parts is that, instead of white cards, there should be a single text box with a button to submit. When I press submit, nothing happens - The Javascript alert doesn't fire or anything.

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);
});

I'm new to Node.JS, AngularJS, and Javascript, so I'm probably missing something obvious. Any help is appreciated!

6
  • I suppose you have ng-controller and ng-app somewhere, right? Have you set a breakpoint in your controller to see that it is loading it? Commented Jul 24, 2016 at 3:00
  • No, that must be it. Where do they go? Sorry for the stupid question. Commented Jul 24, 2016 at 3:02
  • Can you please provide jsfiddle or plunker for your problem? Commented Jul 24, 2016 at 3:03
  • ng-app can go in the body tag. ng-controller should probably be in the outermost div element so that it encloses all elements with function calls Commented Jul 24, 2016 at 3:03
  • @mparnisari In game.html, right? Commented Jul 24, 2016 at 3:06

1 Answer 1

2

Issues is typo error with selectSituation in controller. For now it is $scope.selectSituaton while it should be $scope.selectSituation.

Try with below code:

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

I believe it will resolve your issue.

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.