1
for (let i = 0; i < newsValues.length; i++) {
  this.newsX[newsValues[i]] = {
    title: newsValues[i].title,
    date: newsValues[i].published_on,
    url: newsValues[i].url,
    body: newsValues[i].body,
    image: newsValues[i].imageurl,
    tags: newsValues[i].tags
  };
}    

Here I get the response, and I made my own object with properties I need, everything works except the image when I pass it through *ngFor.

this is my Html part:

<nz-layout>
    <nz-content>
      <header>
        <h1>Cool Articles</h1>
      </header>
      <div class="band">
        <div class="item-7" *ngFor="let news of newsData">
          <a href="{{news.url}}" class="card">
            <div class="thumb" [style.background-image]="'url('+news.image+')'">
            </div>
            <article>
              <h1>{{news.title}}</h1>
              <span>Release Date: {{news.date | date: 'yyyy-MM-dd'}}</span>
            </article>
          </a>
        </div>
      </div>
   </nz-content>
</nz-layout>
4
  • 1
    must be work, see the value of news.images (if starts with a "/" or not, if is in the correct directory... Commented Mar 18, 2021 at 13:48
  • Goes like this Imageurl: "images.cryptocompare.com/news/default/ethereumworldnews.png" Commented Mar 18, 2021 at 13:50
  • I should suppose should be [style.background-image]="'url(https://'+news.image+')'". Else Angular try to find your image in a directory images.cryptocompare.com/news/default Commented Mar 18, 2021 at 17:12
  • Angular looks the files according the base href tag. if we don't put a "/" before the image, e.g. <img src="assets/images/imagen.jpg"> and base href is '/' and our app is in the directory c:/myapp, look for the file in c:/myapp/assets/images/imagen.jpg. In this case is equal use /assets/.... If your base href is another (imagine a multilanguage app where base href="/es-ES", if we don't put the / search in c:/myapp/es-ES/assets/images/imagen.jpg Commented Mar 18, 2021 at 17:18

3 Answers 3

1
  • Check if 'news.image' value has http/https protocol. If not you might have to add it to the original array or in the template.

    image: newsValues[i].imageurl, //Check for http/https 
    
  • Make sure 'thumb' class has a height & width property attached to it.

Stackblitz - https://stackblitz.com/edit/angular-ewpahe?file=src/app/app.component.ts

Sign up to request clarification or add additional context in comments.

Comments

0

why you are not using img tag?

<img [src]="news.image" ...../>

1 Comment

I tried that too, but only broken image thumbnail and empty div
0
<img src = {{movie.Poster}} /> 

Works for me, after trial and error

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.