我使用 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");
}
}
});
我该如何解决这个问题,或者是否有更好的方法来做到这一点。
更新:
在给定时间图像不一样,我想使用它们的索引访问每个图像的索引。
更新: 我添加了这个示例,如何修改例如具有“文本 2”的图像