在ng-repeat中注入图像src时出错

时间:2015-01-30 18:38:57

标签: javascript angularjs

src注入图像时出现JavaScript错误。

<button ng-repeat="child in user.childArray" class="well"  ng-click="selectChild(child);"><img src="{{child.childImage}}"><br />{{child.childName}}</button>

我将child.childImage作为src的{​​{1}}元素。当我这样做时,我在控制台中收到以下错误。

img

如果我没有将其作为GET http://localhost:8000/app/%7B%7Bchild.childImage%7D%7D 404 (Not Found) angular.js:2918 forEach.html angular.js:2965 JQLite.(anonymous function) angular-route.js:901 link angular.js:8217 invokeLinkFn angular.js:7726 nodeLinkFn angular.js:7075 compositeLinkFn angular.js:6954 publicLinkFn angular.js:7093 $get.boundTranscludeFn angular.js:7753 controllersBoundTransclude angular-route.js:865 update angular.js:14707 $get.Scope.$broadcast angular-route.js:547 (anonymous function) angular.js:13175 processQueue angular.js:13191 (anonymous function) angular.js:14388 $get.Scope.$eval angular.js:14204 $get.Scope.$digest angular.js:14493 $get.Scope.$apply angular.js:9650 done angular.js:9840 completeRequest angular.js:9781 requestLoaded ,我就不会收到错误。

img src

1 个答案:

答案 0 :(得分:3)

将src更改为ng-src

<button ng-repeat="child in user.childArray" class="well"  ng-click="selectChild(child);"><img ng-src="{{child.childImage}}"><br />{{child.childName}}</button>