http://localhost:3501/%7B%7Bparcel.image%7D%7D
是http://localhost:3501/{{parcel.image}}
记住,HTML实际上是在DOM时的角度进行编译。因此,您的浏览器(对于一个短暂的时刻,应用程序白手起家之前),其在DOM是这样的:
<div class="parcel-image" style="background-image:url({{parcel.image}})">...</div>
而当它看到的样式属性,它击中/{{parcel.image}}
您的服务器。
这就是为什么你偶尔会遇到404。
编辑:您可以使用the ngStyle directive来解决这个问题:
的ngStyle
指令将观看对象,并将其应用于包含样式。
因此,在你的HTML:
<div class="parcel-image" ng-style="styles">...</div>
而在你的控制器:
app.controller('ParcelImageController', function($scope) {
$scope.parcel = {/*some object*/};
$scope.style = {
'background-image': 'url(' + $scope.parcel.image + ')'
};
});
Here a fiddle with an example of this in action.
'风格=“背景图像:网址({{parcel.image}}) ;'不关闭 – iMom0 2013-02-15 12:34:55
@ iMom0,这里只是一个拼写错误,修正了,谢谢。在源代码中没有问题。 – 2013-02-15 12:39:45