更新ng repeat using指令创建的图像

Update images created by ng-repeat using directive

本文关键字:创建 图像 指令 using ng repeat 更新      更新时间:2023-09-26

我使用sockte.io从服务器获取数据,根据数据(item.text),我必须更改图像。我试图访问DOM并使用指令修改图像,但没有成功。

这是我的代码:

HTML:

<table>
    <tr ng-repeat="item in items"  myDirective>
        <td><img  ng-src="{{myImages}}" ></td> <td>{{item.text}}</td>
    </tr>
</table>

JS:

App.directive('myDirective', function(){
  return {
    link: function($scope, elm){
      console.log('eee', elm);
      elm[0]['children'][0]['children'][0].attr('src',"/url/to/the/image");
    }
  }
});

我该如何解决这个问题,或者是否有更好的方法。

更新:

在给定的时间,图像不相同,我想使用它们的索引访问每个图像的索引。

更新:我添加了这个示例,例如,我如何修改具有"text 2"的图像

对此不需要指令。对图像使用ng-src,而不是普通的src属性。