Oce*_*uto 1 javascript image angularjs
我有角度的以下代码.
<img class="img-circle image-stroke" ng-src="{{person.photo}}" onerror="this.src='http://www.clker.com/cliparts/5/9/4/c/12198090531909861341man%20silhouette.svg.hi.png'"></img>
Run Code Online (Sandbox Code Playgroud)
我从数据库中获取一个人物对象photo,其中包含该人物照片的网址.问题是,有时这个值将为null.正如您所看到的,我已使用onerrror标记中的属性处理它,因此每当它为null并ng-src抛出错误时,它将回退到默认图像.
问题是,它仍然会在控制台中抛出以下错误.
GET http://localhost:3000/module/seasons/person.photo 404 (Not Found)
有没有办法压制这个错误?在制作中,很可能会有12或13个人一次没有照片值,我不希望我的老板在控制台中看到12或13个错误,即使实际网站上没有任何内容.
只有在src不为null且以其他方式呈现备份映像时才能呈现:
<img ng-if="person.photo" class="img-circle image-stroke" ng-src="person.photo"></img>
<img ng-if="!person.photo" class="img-circle image-stroke" src="http://www.clker.com/cliparts/5/9/4/c/12198090531909861341man%20silhouette.svg.hi.png"></img>
Run Code Online (Sandbox Code Playgroud)