[英]Getting error with ng-if in angularjs
I am using ng-if
tag in my app, but it seems like when I load the page, it throws an error. 我在我的应用程序中使用ng-if
标签,但似乎当我加载页面时,它会抛出错误。
Here is how my code looks like 这是我的代码的样子
<ons-col width="95px">
<img src="{{PostDetail.attachments[0].images.square1.url}}" class="thumbnail" ng-if="PostDetail.attachments[0].url != null">
<img src="images/location1.png" class="thumbnail" ng-if="PostDetail.attachments[0].url == null">
</ons-col>
When a page loads or when I reload it shows this below error: 页面加载或重新加载时显示以下错误:
GET file://localhost/Volumes/Work%20Data/Development/Come%20to%20woodstock%20Ic…o%20Woodstock/www/%7B%7BPostDetail.attachments[0].images.square1.url%7D%7D net::ERR_FILE_NOT_FOUND GET文件://localhost/Volumes/Work%20Data/Development/Come%20to%20woodstock%20Ic...o%20Woodstock/www/%7B%7BPostDetail.attachments [0] .images.square1.url%7D%7D net: :ERR_FILE_NOT_FOUND
Is there any problem in the ng-if
? ng-if
有什么问题吗? It looks good while it works on browser, but when I load the console in my google chrome, I can see some of these above mentioned weird errors. 它在浏览器上运行时效果很好,但是当我在谷歌浏览器中加载控制台时,我可以看到上面提到的一些奇怪的错误。 Any solutions? 有解决方案吗
To avoid a browser eagerly retrieving the image from a not-yet-interpolated URL, eg src="{{some.url}}"
(thus resulting in HTTP error), you should use ng-src
: 为了避免浏览器急切地从尚未插值的URL中检索图像,例如src="{{some.url}}"
(从而导致HTTP错误),您应该使用ng-src
:
<img ng-src="{{PostDetail.attachments[0].images.square1.url}}">
As for your ng-if
, it seems to guard against a null PostDetail.attachments[0].url
- are you sure you didn't mean PostDetail.attachments[0].images.square1.url
? 至于你的ng-if
,它似乎防止了一个null的PostDetail.attachments[0].url
- 你确定你不是指PostDetail.attachments[0].images.square1.url
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.