angularJS中如何使img实现数据双向绑定?

<ul class="block-pics clearfix">

                           <li id="img{% raw %}{{$index}}{% endraw %}" class="clearfix" ng-repeat="img in items.config.imgs">
                             <a href="{% raw %}{{img.url}}{% endraw %}" class="big"><img ng-src="{% raw %}{{img.url}}{% endraw %}"></a>
                         </li>
                        </ul>
                 
                 
app.controller('templateController', function($scope) {
    $scope.items=[{"config":{"style":"v3","is_show":1,"imgs":[{"url":"../path/abc.jpg","position":1,"link":"abc.html"},{"url":"../path/abc2.jpg","position":2,"link":"dsdsfd.html"}],"position":1},{"config":{"style":"v2","is_show":1,"imgs":[{"url":"../path/abc11.jpg","position":1,"link":"abc222.html"},{"url":"../path/abc2222.jpg","position":2,"link":"dsdsfd11.html"}],"position":2}]
});

期望img的src被改变时,$scope.items中的img.url也会同步改变;

回复
阅读 3.4k
1 个回答

你怎么改变img的src?
img的src只能通过JS代码改变,你为什么不在JS 操作img的src的时候直接改变items数组里的内容呢?
你要上直接F12控制台修改img的src的话,那么只能自己写个指令,监听img的src属性,检测到改变然后修改items数组

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏