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

时间:2023-01-14 22:57:13

I have setup a simple ng-click function on a div that once clicked should change the color of a different div. Simple enough except it only works on first time I click the div...then nothing :( I am just trying to get functionality for a toggle function which I will use all over for different things.

我在div上设置了一个简单的ng-click功能,一旦点击就应该改变不同div的颜色。很简单,除了它只在我第一次点击div ...然后没有任何东西:(我只是试图获得切换功能的功能,我会用于不同的东西。

HTML: (this code is part of a loop)

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>

Controller:

控制器:

$scope.colorblur="red";

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

Thanks in advance :)

提前致谢 :)

2 个解决方案

#1


3  

change

更改

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

to

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

#2


3  

use === instead of =

使用===而不是=

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

#1


3  

change

更改

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

to

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

#2


3  

use === instead of =

使用===而不是=

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