admin管理员组文章数量:1431413
In angular version 1 i use ng-src to load an url. In angular 2 Js for Dart i can't find a similar method to load resources. For example in Angular 1 js:
<img class="cover" src="images/cover_placeholder.png" data-ng-src="{{coverUrl}}"
in Angular 2 js i have already tried:
<img class="cover" src="{{coverUrl}}">
How i can load a placeholder in case of image is not available? There areothers smart ways to do that?
EDIT Solved in this way:
<img class="class-image" onError="this.src='./images/cover_placeholder.png';" src="{{coverUrl}}" >
If image is not avaible place the Placeholder image.
In angular version 1 i use ng-src to load an url. In angular 2 Js for Dart i can't find a similar method to load resources. For example in Angular 1 js:
<img class="cover" src="images/cover_placeholder.png" data-ng-src="{{coverUrl}}"
in Angular 2 js i have already tried:
<img class="cover" src="{{coverUrl}}">
How i can load a placeholder in case of image is not available? There areothers smart ways to do that?
EDIT Solved in this way:
<img class="class-image" onError="this.src='./images/cover_placeholder.png';" src="{{coverUrl}}" >
If image is not avaible place the Placeholder image.
Share Improve this question edited Mar 21, 2016 at 11:59 Andrea Bozza asked Mar 16, 2016 at 16:18 Andrea BozzaAndrea Bozza 1,3842 gold badges12 silver badges31 bronze badges 6- what do you mean with image not available? is the variable undefined or the image returns a 404 – juvian Commented Mar 16, 2016 at 16:21
- get to the image url returns a 404 – Andrea Bozza Commented Mar 16, 2016 at 16:22
- Are you using a directive? Don´t see how that case would be resolved with angular 1 – juvian Commented Mar 16, 2016 at 16:28
- i use dart with angular2 Javascript – Andrea Bozza Commented Mar 16, 2016 at 16:42
- You would probably need to do something like this but with angular2: stackoverflow./questions/16349578/… – juvian Commented Mar 16, 2016 at 16:45
1 Answer
Reset to default 3It will depend on when you are getting the error. If it is erroring on load, it is because Angular hasn't kicked off by the time the html is loaded and so the url cannot be interpreted.
In AngularJS, this was circumvented by using ng-src
The Angular two equivalent is to use [src]=""
<img class="cover" [src]="coverUrl">
本文标签: javascriptngsrc in Angular 2 js with DartStack Overflow
版权声明:本文标题:javascript - ng-src in Angular 2 js with Dart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745566040a2663766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论