2017-09-16 79 views
0

我已经从类似问题的人那里看过多个问题线索,但他们没有解决我的问题。Ng-repeat不更新视图

这是全码(Exluding的CSS部分:

<script>          

    var app = angular.module("game", []); 
    app.controller("controlematrix",function($scope) 
     { 
      $scope.undo = []; 
      $scope.matriz = [ 2,2,2,2,2,2,2 
          ,2,2,2,0,0,0,2 
          ,2,3,0,0,0,0,2 
          ,2,0,0,0,0,0,2      
          ,2,3,0,0,2,0,2 
          ,2,0,0,0,0,0,2 
          ,2,2,2,2,2,2,2]; 

      $scope.posx = 5; 
      $scope.posy = 3; 

      $scope.testeshow= function(atual){     
       return (($scope.posx + $scope.posy * 7) != atual); 
      } 

      $scope.up = function() { 
       if($scope.matriz[$scope.posx + ($scope.posy-1) * 7] != 2) 
       { 
        $scope.posy--; 
       } 
      } 
      $scope.down = function() { 
       if($scope.matriz[$scope.posx + ($scope.posy+1) * 7] != 2) 
       { 
        $scope.posy++; 
       } 
      } 
      $scope.left = function() { 
       if($scope.matriz[($scope.posx-1) + $scope.posy * 7] != 2) 
       { 
        $scope.posx--; 
       } 
      } 
      $scope.right = function() { 
       if($scope.matriz[($scope.posx+1) + $scope.posy * 7] != 2) 
       { 
        $scope.posx++; 
       } 
      } 

     }); 
</script> 

<div id="everything" ng-app="game" ng-controller="controlematrix" > 
    <div id="container"> 
     <div class="item" ng-repeat= "x in matriz track by $index"> 
      <img ng-src="{{'tile' + x +'.png'}}" alt="tile" ng-show= "{{testeshow($index)}}"> 
      <img ng-src="player.png" alt="player" ng-show= "{{!testeshow($index)}}"> 
     </div> 
    </div> 
    <div id="buttonscreen"> 
     <button class="botao" ng-click="up()">UP</button> 
     <button class="botao" ng-click="down()">DOWN</button> 
     <button class="botao" ng-click="left()">LEFT</button> 
     <button class="botao" ng-click="right()">RIGHT</button> 

    </div> 

</div> 

调试之后,似乎POSX和POSY值更新等他们应该但屏幕上的图像保持不变。我似乎无法找到概率lem是。如果有人能帮忙,我会非常感激。

回答

1

变化ng-show="{{testeshow($index)}}"ng-show="testeshow($index)"ng-show需要一个表达式。

+1

如果您的答案与其他人不同,请写下答案。谢谢 –

1

删除{{}}ng-show

<img ng-src="{{'tile' + x +'.png'}}" alt="tile" 
    ng-show= "testeshow($index)"> 
<img ng-src="player.png" alt="player" 
    ng-show= "!testeshow($index)"> 

Demo