ng-src在img标记上需要非空的src属性

时间:2014-08-18 17:16:20

标签: angularjs

ng-src shows that using ng-src by itself should work的文档。但是,当我尝试在我的图像上使用它时,除非我使用某些文本指定了src属性,否则图像不会显示。

以下不起作用:

<img ng-src="{{img.url}}" />

以下作品:

<img src="placeholder_text" ng-src="{{img.url}}" />

1 个答案:

答案 0 :(得分:-1)

尝试

{{img}}

而不是

{{img.url}}

http://plnkr.co/edit/Z55CZxaEx92XztKP8Nhn?p=preview

加载HTML时,ngSrc指令应创建一个带有ng-src属性URL的src属性。从plnkr示例:

输入HTML:

<img ng-src="{{img}}" />

JS:

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.img = 'http://mawords.com/images/plnkr.co.gif';
});

输出HTML

<img ng-src="http://mawords.com/images/plnkr.co.gif" src="http://mawords.com/images/plnkr.co.gif">
相关问题