2

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.

Andrea Bozza
  • 1,374
  • 2
  • 12
  • 31

1 Answers1

3

It 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">
Graham
  • 7,431
  • 18
  • 59
  • 84
Des Horsley
  • 1,858
  • 20
  • 43