Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda