ng-click功能仅在第一次有效

问题描述 投票:0回答:2

我在div上设置了一个简单的ng-click功能,一旦点击它就会改变不同div的颜色。很简单,除了它只适用于我第一次点击div ...然后没有:(我只是想获得一个切换功能的功能,我将用于不同的事情。

HTML :(此代码是循环的一部分)

<img ng-click="changer()" src="{{m.img}}" style="width:100%;min-height:480px;max-height:600px;z-index:1;"> 

...

<div style="background-color:{{colorblur}}; width:100px;height:100px;"></div>

控制器:

$scope.colorblur="red";

  $scope.changer = function () {  
        if($scope.colorblur="red"){
          $scope.colorblur="yellow";
        }
        else{
          $scope.colorblur="red";
        }
    } 

提前致谢 :)

javascript html angularjs ionic-framework
2个回答
4
投票

更改

 if($scope.colorblur="red"){..

 if($scope.colorblur === "red"){...

3
投票

使用===而不是=

if($scope.colorblur === "red"){
© www.soinside.com 2019 - 2024. All rights reserved.