AngularJS ng-repeat不重复,没有控制台错误

时间:2017-08-03 00:32:31

标签: javascript angularjs

我正在使用AngularJS和角度材料开始一个简单的井字游戏。作为其中的一部分,我尝试使用ng-repeat重复一组md-buttons,但重复不起作用。它看起来应该对我有用,看起来很像我见过的其他解决方案,所以可能有一些简单的我想念,但我无法弄明白。有什么建议吗?

这是我的HTML:

  <div ng-app="ticTacToe">

  <h1>Tic Tac Toe</h1>

  <div ng-controller="TicTacToeCtrl">
    <div layout="row">
      <md-button ng-repeat="cell in vm.board[0]">{{cell.value}}</md-button>
    </div>

    <div layout="row">
      <md-button ng-repeat="cell in vm.board[1]">{{cell.value}}</md-button>
    </div>

    <div layout="row">
      <md-button ng-repeat="cell in vm.board[2]">{{cell.value}}</md-button>
    </div>
  </div>
</div>

我的javascript:

(function() {
  'use strict';
  angular.module('ticTacToe', ['ngMaterial'])
  .controller('TicTacToeCtrl', function($mdDialog) {
      var vm = this;
      vm.board = [
        [{id: 1, value: ''}, {id: 2, value: ''}, {id: 3, value: ''}],
        [{id: 4, value: ''}, {id: 5, value: ''}, {id: 6, value: ''}],
        [{id: 7, value: ''}, {id: 8, value: ''}, {id: 9, value: ''}]
      ];
      vm.symbol = '';
      vm.victoryConditions = [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
        [1, 4, 7],
        [2, 5, 8],
        [3, 6, 9],
        [1, 5, 9],
        [3, 5, 7]
      ];

      var init = function() {
        var popup = $mdDialog
          .confirm()
          .title("Tic Tac Toe")
          .textContent("Pick a side.")
          .ok("O")
          .cancel("X");
        $mdDialog.show(popup).then(
          function() {
            vm.symbol = "O";
          },
          function() {
            vm.symbol = "X";
          }
        );
      };
      init();
    });
})();

1 个答案:

答案 0 :(得分:1)

问题在于您没有将控制器定义为。改变这个:

C:\leveltwo\assigntwo\blogModel.js:19 
  userName        : {type:String,default:''} 
    ^^^^^^^^ 
SyntaxError: Unexpected identifier 
at createScript (vm.js:56:10) 
at Object.runInThisContext (vm.js:97:10) 
at Module._compile (module.js:542:28)

 because of the above problem i am unable to create a new entries in the 
 project and even my  postman is also not responding.
 please reply if anyone knows ..... thank you.