Using ngFor to display images with src attribute, merging information from two different properties within the loop

One issue I am facing involves an array with properties:

export interface IGameTag{
  name: string;
  relativePath: string;
  filename: string;
}

I understand that it is possible to include the filename in the relativePath like this:

<div *ngFor="let gameTag of gameTags">
   <img [src]="gameTag.relativePath">
</div>

However, my requirement is to combine the filename with the relativePath. When I try to do this, it results in a compiler error in html:

<div *ngFor="let gameTag of gameTags">
   <img [src]="gameTag.relativePath + '\\'+ gameTag.filename">
</div>

The error message reads:

main.e7b5b0b437c5d1b16f1f.js:185910 Error: Errors during JIT compilation of template for GameCardComponent: Parser Error: Unexpected token '{' at column 2 in [${gameTag.relativePath}\${gameTag.filename}]

As requested, here is a sample value for relativePath:

relativePath = assets\image
fileName = 123456789.png

Answer №1

Have you attempted the suggestions below?

<div *ngFor="let gameTag of gameTags">
   <img [src]="`${gameTag.relativePath}\${gameTag.filename}`">
</div>

OR

<div *ngFor="let gameTag of gameTags">
   <img src="{{gameTag.relativePath}}\{{gameTag.filename}}">
</div>

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

What is the best way to create a React component that renders a class component as a functional component?

My Objective: At the moment, I am in the process of developing an AuthUserRole HOC component to manage user roles like Manager and Employee. However, I encountered a tutorial that uses a functional component to return a class component as referenced here. ...

Playwright script encounters module not found error

I am currently facing an issue with implementing Playwright in my project. It seems that Playwright is struggling to a) resolve path aliases and b) it is unable to locate certain npm packages that have been installed. Here is the structure of my project: ...

Adding a new key to a specific position in an array using Angular

After organizing my array, here is what it currently looks like: 0: Object { row: 0 } 1: Object { row: 1 } 2: Object { row: 2 } 3: Object { row: 3 } Now, I need to add a new key to position 2. The updated structure should resemble this: 0: Object { row: 0 ...

Struggling to locate the module in React Native with TypeScript configuration

Currently, I am in the middle of transitioning our react-native project from JavaScript to TypeScript. As I attempt to import old modules, I keep encountering the following error: Cannot find module 'numeral' Oddly enough, the 'numeral&apo ...

Filtering nested arrays in Angular by cross-referencing with a navigation menu

In the legacy application I'm working on, we have a navigation menu along with a list of user roles. Due to its legacy nature, we have accumulated a significant number of user roles over time. The main goal is to dynamically display the navigation me ...

When the route changes, routerCanReuse and routerOnReuse are not invoked

I am currently exploring the functionalities of Angular2's Router, specifically focusing on OnReuse and CanReuse. I have followed the documentation provided here, but I seem to be encountering difficulties in getting the methods to trigger when the ro ...

How can a new component be added as a child of an element without replacing or interfering with other

Whenever I dynamically generate components and attach them as children to an element upon creation, everything within that element gets deleted. Here's an example: public fn(event) { // Create component factory const factory = this.componentF ...

Is Highcharts-angular (Highcharts wrapper for Angular) compatible with Angular 4?

I have attempted to install various versions of highcharts-angular, ranging from 2.0.0 to 2.10.0. However, I consistently encounter the same error when running the application. The error message states: Metadata version mismatch for module C:/dev/Angular- ...

Leverage a custom server (such as NestJS) within NextJS to dynamically render targeted pages

I am experimenting with using NestJS as a custom server for NextJS, following the instructions in this article. Here is a simplified version of the code: @Controller('/') export class ViewController { @Get('*') async static(@Req() r ...

What could be causing my controller method in TypeScript to throw an error message unexpectedly?

Hey there. I'm diving into TypeScript and currently working on converting an Express backend to TS. Everything was smooth sailing until I encountered some unexpected issues. Specifically, the lines const hasVoted = poll.votedBy.some((voter): boolean = ...

Tips for sending the updated position of the marker to a function

When using the following code, the intention is to pass a dragged marker LatLng into a function in order to obtain an address. However, there seems to be an issue with this process. public LastLat : any; public LastLng : any; . . . lastLatLng(marker){ ...

I recently upgraded my Angular version from 5 to 8, and encountered an unexpected error with the toastr plugin

I recently upgraded my Angular version from 5 to 8 and encountered an issue. Upon starting the server with 'ng serve', I received the following error in the console: Uncaught TypeError: core_1.style is not a function at Object../node_modules/ng ...

What is the best way to compare two arrays that have elements of different data types?

Can someone help me compare two arrays in TypeScript to see if they are identical? I'm having trouble with the current code. Here's what I have: let props:(string|boolean)[]=['abc','def',true,false,'xyz'] let propsCo ...

Is there a method to add columns to an Angular material table dynamically?

I'm encountering an issue with creating dynamic tables using Angular Material tables. Since the table is reliant on an interface, I have a set number of columns. What I'm aiming for is to generate a table dynamically based on the server's re ...

Combine individual websites that have been deployed separately into a single website and display them using a uniform base URL

I have multiple website projects deployed on separate subdomains with their specific resources. I want to create a launch/landing subdomain website that allows users to access each website in different subdomains through the menu, without changing the subd ...

What is the process for setting up a Quill Editor within an Angular 2 Component?

I am currently working on creating my own Quill editor component for my Angular 2 project. To integrate Quill into my project, I utilized npm for installation. My goal is to develop a word counter application using this component and I am referring to the ...

Changing the time in Angular while converting a string to a date object has proven to be

Can anyone help me with a problem I'm having trying to convert a String into a Date object without it being affected by timezone changes? Specifically, when I receive 2020-07-14T15:27:39Z from an http get request, I need to convert this into a Date o ...

Adding the highcharts-more.src.js file to an Angular 2 project: A step-by-step guide

I have linked highcharts-more to the system variable: 'highcharts-more': 'node_modules/highcharts/highcharts-more.src.js' But I keep getting an error message saying: Error in dev/process/templates/detail.template.html:40:33 ORIGINAL ...

Sharing Pictures and Messages using angular, express, and multer

Struggling with posting images and text to the server while self-learning Angular. The backend works fine in Postman testing, but fails when working with Angular. Here is the code snippet I have been using: upload.component.html <form [formGroup]="upl ...

The module 'json-stringify-safe' could not be located

Encountering an issue while executing the command - ionic serve The code was functioning properly on a different system but seems to be causing trouble for me at the moment. ...