When utilizing dynamic binding within *ngfor in Angular 4, the image fails to display properly

I'm encountering an issue with an <img> tag that isn't behaving as expected in my code snippet:

<div  *ngFor="let familyPerson of userDataModel.family" class="col-md-6 col-lg-4 family-member">
   <div class="fm-wrapper">
      <div class="round-frame-bg">
         <div class="round-frame wow animated">
            <img [src] = 'familyPerson.image'>
         </div><!-- /.round-frame -->
      </div><!-- /.round-frame-bg -->

      <p>{{familyPerson.qualities}}</p>
  </div><!-- /.hide -->
</div><!-- /.col-md-4-->

userDataModel.family represents family members' properties in JSON format.

The src attribute is correct, but the image is not displaying in the browser.

Despite network activity showing the image has loaded, it remains invisible.

Oddly enough, replacing the <img> tag with one having a hardcoded src results in the image displaying properly.

What could be causing this issue and how might I resolve it?

Answer №1

<img [src] = "familyPerson.image">

Personally, I believe the code above should function correctly. In order to access the value from a variable, it is necessary to use double quotes.

<img src = "{{ familyPerson.image }}">

In my opinion, this alternative code should also be effective.

Answer №2

http://localhost:4200/assets/images/{{familyPerson.image}}
This works because the image may have been saved with the same name in your assets/images directory. You are receiving only the image name from the server, not the complete URL. It is recommended to fetch the full image URL from the server like http://localhost:3000/assets/images/abc.png, or you can obtain just "abc.png" and modify the server path manually.
Ensure that the images are stored on the server side so they are accessible when needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Grid of domes, fluid contained within fixed structures and beyond

I've been grappling with this issue for a while now, and have had to rely on jQuery workarounds. I'm curious if there is a way to achieve this using CSS or LESS (possibly with javascript mixins). The page in question consists of both fixed and f ...

Difficulty updating Angular packages using NCU (npm-check-update)

I attempted to update everything on my project by running the following commands: G:\Projects\salarkazazi> npm i -g npm-check-updates The output displayed the following warnings: npm WARN deprecated [email protected]: this library is n ...

Side Menu with Fixed Position Created with Tailwind CSS

Can anyone help me create a social media sidebar that stays fixed on the bottom right side of the screen, regardless of its size? Currently, the sidebar moves when I scroll down, but I want it to remain in place. How can I achieve this fixed positioning? ...

Error when building Angular 9 due to missing peer dependencies

In my coding project, there is a specific npm module that has a dependency on electron. The functionality from this module is accessed within a function and only executed when necessary, allowing it to be utilized in both electron-based projects as well as ...

Discover the way to create an HTML button with a mesmerizing transparent effect

For my website creation using Dreamweaver, I came up with the idea of utilizing Photoshop to design backgrounds. The reasoning behind this choice was that if I needed to modify button names at any point, I could simply edit the code and make the necessary ...

The system encountered a TypeError: Unable to access the 'nativeElement' property as it is undefined

Hello, I am a beginner in Angular 2 and currently working on an image cropping plugin. My goal is to display the image on a canvas element. Below is my HTML code: <div class="row"> <div class="col-sm-6"> <canvas id="layout" width="40 ...

Error message: Cordova not found - unable to use 'ionic native' 3 for CRUD operations with SQLite database

I am attempting to manage CRUD data with SQLite in Ionic 3, but unfortunately cordova is not functioning as expected. https://i.sstatic.net/5m411.png ...

Jquery Parallax causing scrolling problems across different browsers

Could you please take a look at the following link in both Chrome and Firefox? I am encountering some unusual issues. Primary Concern The scrolling function works smoothly in Firefox, but it seems to be malfunctioning in Chrome. Secondary Problem Whe ...

Tips for ensuring that divs resize to match the container while preserving their original proportions:

#container { height: 500px; width: 500px; background-color: blue; } #container>div { background-color: rgb(36, 209, 13); height: 100px; } #one { width: 1000px; } #two { width: 800px; } <div id="container"> <div id="one">&l ...

Creating a visually dynamic stack of images using javascript, jquery, and HTML

I'm interested in creating a unique image viewer using javascript/jQuery/HTML that combines elements of a book page flip and iTunes coverflow, optimized for mobile device browsers. I've been searching for tutorials to help kickstart this project, ...

Utilize the grid system from Bootstrap to style HTML div elements

I am working on my angular application and need help with styling items in a Bootstrap grid based on the number of elements in an array. Here's what I'm looking to achieve: If there are 5 items in the array, I want to display the first two items ...

What could be causing the misalignment of these two divs?

I'm struggling to horizontally align these two divs using percentages for width. Even with padding and margin set to 0, they refuse to line up properly (the second one ends up below the first). This is the code I have been using: <div style="widt ...

Uniform dimensions for HTML tables

When creating an HTML document with consecutive tables that need to be formatted the same way, it can be challenging. Browsers will often render columns of one table wider than another simply due to content width. The typical solution is to hard-code colu ...

Extracting Data: Unlocking Information from Websites

My friend and I are working on a school project that involves creating a small application. The main goal of this app is to find pharmacies in our area. I am looking to extract information from two specific websites. gun = day/date lc = id of town ...

Error: SyntaxError - Unexpected token 'if' found. Additionally, ReferenceError - berechnung is not defined

I keep encountering two error messages and I'm not sure where the issue lies: Uncaught SyntaxError: Unexpected token 'if' Uncaught ReferenceError: berechnung is not defined Any idea what might be causing this problem? I've reviewed t ...

How can I resolve the issue of the mouse x/y glitch while drawing on an HTML canvas using JavaScript/jQuery?

I've been searching all over for a solution to this issue, but I just can't seem to find out what's causing the problem... This is my first attempt at working on something like this in my spare time. I hope to apply what I learn to create a ...

Transforming Google Maps from using jQuery to AngularJS

If I have a Jquery google map with find address and routing system, my goal is to convert it to an angular google map with more options. The current Jquery google map code looks like this: var directionsDisplay = new google.maps.DirectionsRenderer({ d ...

What is the method to showcase every single word?

Can someone help me with my assignment? I am tasked with creating a small user interface that searches a list of words using HTML, CSS, and Javascript. The design is provided, but I need to implement it. I have written the code, but I would like all wor ...

What is the best way to fill a dropdown menu with the keys from an object?

Below is an example of the object I have: { "USD": { "symbol": "$", "name": "US Dollar", "symbol_native": "$", "decimal_digits": 2, "rounding": 0, "code": "USD", "name_plural": "US dollars" }, "CAD": { "symbol": "CA$" ...

Angular is unable to iterate through a collection of ElementRef instances

My list of ElementRef contains all my inputs, but adding listeners to them seems to indicate that textInputs is empty even though it's not. @ViewChildren('text_input') textInputs!: QueryList<ElementRef>; ngAfterViewInit(): void { ...