嗨朋友们,我在这里通过选择不同的值来改变文本的值,但我希望图像也能相应地改变。
这里小提琴:http://jsfiddle.net/TU6tp/44/
我们是否应该像文字一样包含图像,同时更改图像也会改变?
代码
<div ng-controller="myCtrl">
<select
ng-model="selectedItem"
ng-options="S.label for S in selectables">
</select>
<p>Selected item value: {{selectedItem.value}}</p>
<p>Selected item image: {{selectedItem.img}}</p>
</div>
我看到另外一个链接http://jsfiddle.net/wktwL/我也很困惑如何在选择时更改图像。请有人帮助我。
答案 0 :(得分:3)
见http://jsfiddle.net/TU6tp/45/,
只需将图像的值放入img
元素
<img src='{{selectedItem}}'/>
$scope.selectables = [
{ label: 'A', value: 'http://upload.wikimedia.org/wikipedia/commons/a/af/Bonsai_IMG_6426.jpg'},
{ label:'B', value:'http://hdwallpaper.freehdw.com/0001/nature-landscapes_widewallpaper_nature-s-beauty_9645.jpg'}
];
您可选择数组的值应包含图像的路径