基于ng click index AngularJS更改图像src

基于ng click index AngularJS更改图像src,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我有这个angularJS代码,指令模板定义: <li ng-repeat="i in getNum(myNum)" ng-click="toggle($index)" id=$index> <img src="img/{{ImgTest}}"> </li> 在ng单击时,我希望在从Img_1单击到Img_2之前更改所有元素上的图像。(因此,更改索引介于0和单击的元素的$index之间的所有元素) 如何做到这一点。。感谢我们可以使用一个由我调用

我有这个angularJS代码,指令模板定义:

<li ng-repeat="i in getNum(myNum)" ng-click="toggle($index)" id=$index>
      <img src="img/{{ImgTest}}">
 </li>
在ng单击时,我希望在从Img_1单击到Img_2之前更改所有
  • 元素上的图像。(因此,更改索引介于0和单击的元素的
    $index
    之间的所有
  • 元素)


    如何做到这一点
    。。感谢

    我们可以使用一个由我调用的变量控制的
    ng开关
    开关点
    通过
    切换()
    设置为
    $index

    切换点之前的所有内容将使用
    ImgTest
    ,而之后的所有内容将使用
    ImgTest2

    这是
    ng开关
    代码(它根据
    开关点
    测试当前的
    $index


    这里有一个提琴(打印{imgTest}}…而不是纯粹为了简单而使用图像):

    现在每个
  • 都会得到相同的图像-Img_1。是否希望在单击ng时全部更改?还是只想更改其中的图像?还是?谢谢Dave的回复。。我想改变从列表开始到列表元素的图像。从列表的第一个元素到该索引。。。任何帮助都将不胜感激。。。真的困在这里了
    link: function (scope, elem, attrs) {            
            scope.ImgTest= "Img_1";
    
    <div ng-switch="switchPoint < $index">
        <div ng-switch-when=true>
            <img src="img/{{ImgTest}}">
        </div>
        <div ng-switch-when=false>
             <img src="img/{{ImgTest2}}">
        </div>
    </div>
    
    link: function (scope, elem, attrs) {            
         scope.ImgTest= "Img_1";
         scope.ImgTest2= "Img_2";
         scope.switchPoint = -1;
         scope.toggle= function(val) {
            scope.switchPoint= val;
        };
    }