Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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">
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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 inside the component. Replace first character of the 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}}">
about 4 years ago · Juan Pablo Isaza Denunciar

0

In 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);

No need to change anything in the template.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda