Javascript Ng重复不更新视图
我读过很多类似问题的人的问题线索,但他们没有解决我的问题 这是完整的代码(不包括CSS部分:Javascript Ng重复不更新视图,javascript,html,angularjs,Javascript,Html,Angularjs,我读过很多类似问题的人的问题线索,但他们没有解决我的问题 这是完整的代码(不包括CSS部分: <script> var app = angular.module("game", []); app.controller("controlematrix",function($scope) { $scope.undo = [];
<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>
var-app=angular.module(“游戏”,[]);
应用程序控制器(“controlematrix”,函数($scope)
{
$scope.undo=[];
$scope.matriz=[2,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=函数(atual){
返回(($scope.posx+$scope.posy*7)!=atual);
}
$scope.up=函数(){
如果($scope.matriz[$scope.posx+($scope.posy-1)*7]!=2)
{
$scope.posy--;
}
}
$scope.down=函数(){
如果($scope.matriz[$scope.posx+($scope.posy+1)*7]!=2)
{
$scope.posy++;
}
}
$scope.left=函数(){
if($scope.matriz[($scope.posx-1)+$scope.posy*7]!=2)
{
$scope.posx--;
}
}
$scope.right=函数(){
如果($scope.matriz[($scope.posx+1)+$scope.posy*7]!=2)
{
$scope.posx++;
}
}
});
向上的
向下
左边
正确的
调试后,posx和posy值似乎正在更新,但屏幕上的图像保持不变。我似乎找不到问题所在。如果有人能帮助我,我将不胜感激。从
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)">
从
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)">
将
ng show=“{{testeshow($index)}}”更改为ng show=“testeshow($index)”
。需要一个表达式。将ng show=“{{testeshow($index)}”更改为ng show=“testeshow($index)”
。需要一个表达式。如果您的答案与其他答案不同,请写下答案以防万一。谢谢如果您的答案与其他答案不同,请写下答案以防万一。谢谢