NG-CLICK功能仅在第一次工作

ng-click function only works the first time

本文关键字:第一次 工作 功能 NG-CLICK      更新时间:2023-09-26

我在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";
        }
    } 

提前致谢:)

更改

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

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

使用 === 而不是 =

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