Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
i want replace ~ to become URL backend, <img alt="" src="~/media/Banner/plane.JPG"> 404 not found

1. I got HTTP Request, response JSON, from backend localhost:3000 (value inputed using wysiwyg)

{
"Description": "&lt;img alt=&quot;&quot; src=&quot;~/media/Banner/plane.JPG&quot; /&gt;1 test berita&lt;br /&gt;\r\n&amp;nbsp;"
}

2. in Angular html,

<div [innerHTML]="data.description | safeHtml"></div>

(already decoded in component.ts)

3. In the browser,

<div>
  <img alt="" src="~/media/Banner/plane.JPG">1 test berita<br>
  &nbsp;
</div>

4. The error is

GET http://localhost:4200/~/media/Banner/plane.JPG 404 (Not Found)

That error is because the URL was wrong. It should be using backend URL http://localhost:3000/media/Banner/plane.JPG

I want to replace every ~ with http://localhost:3000.

<img alt="" src="~/media/Banner/plane.JPG">
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

STEP 1

Define backend_URL in the environment.ts file:

 export const environment = { backend_URL: 'http://localhost:3000/' };

STEP 2

Import environment from environment.ts into the component. Replace the first character of data.src with environment.backend_URL .

 import { environment } from '../environments/environment'; public backend_URL = environment.backend_URL; data.src = this.backend_url + data.src.substring(1);

STEP 3

Use data.src in the component.

 <img src="{{ data.src}}">
over 4 years ago · Santiago Trujillo Report

0

In the ts file:

 // This could be from your environment file const backendURL ="http://localhost:3000"; const obj = { "Description": "&lt;img alt=&quot;&quot; src=&quot;~/media/Banner/plane.JPG&quot; /&gt;1 test berita&lt;br /&gt;\r\n&amp;nbsp;" }; obj['Description'] = obj['Description'].replaceAll('~', backendURL); console.log(obj);

You don't need to change anything in the template.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!