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

141
Visualizações
Image does not show up with Angular ngx-translate

I am using ngx-translate with Angular. I want to change an image depending on the language used in the application. The thing is that I can´t change the image when I click a language. I have two languages 'en' and 'es'.

This is my 'header.component.html'. This is the component which has the menu of the application. As you can see there is an 'updateSrc()' function in the click attribute.

<div class="select-box__current" tabindex="1">

  <div class="select-box__value" (click)="useLanguage('es');updateSrc(second_url);">
      <input class="select-box__input" type="radio" id="0" value="1" />
      <p class="select-box__input-text">es</p>
  </div>

  <div class="select-box__value" (click)="useLanguage('en');updateSrc(first_url);">
     <input class="select-box__input" type="radio" id="1" value="2" checked="checked"/>
     <p class="select-box__input-text">en</p>
  </div>

</div>


Also I have another component 'looker.component.html' where the image have to change.


<div class="map">

    <img class="graph" src="{{first_url}}" alt="graph">

</div>

And this is my 'looker.component.ts' where I am not sure how to write the updateSrc() function in order to change the other URL when someone clicks one of the two languages.


import { Component, OnInit, PLATFORM_ID, Inject } from '@angular/core';
import { Meta, Title } from '@angular/platform-browser';

@Component({
  selector: 'app-looker',
  templateUrl: './looker.component.html',
  styleUrls: ['./looker.component.scss']
})
export class LookerComponent implements OnInit {

  first_url: string = "https://storage.googleapis.com/amarello-web-assets/img/graph_2.svg";
  second_url: string = "https://storage.googleapis.com/amarello-web-assets/img/graph_1.svg";

  constructor(
    private title: Title,
    private meta: Meta,
    @Inject(PLATFORM_ID) private platformId: Object
  ) { }

  ngOnInit(): void {
      this.first_url;
  }

  updateSrc(url) {   


  }


}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use property binding on [src] which will take the value of the property first_url then on the change event just update the property as shown below!

html

<div class="map">
    <img class="graph" [src]="first_url" alt="graph"> <!--  changed here -->
</div>

ts

import { Component, OnInit, PLATFORM_ID, Inject } from '@angular/core';
import { Meta, Title } from '@angular/platform-browser';

@Component({
  selector: 'app-looker',
  templateUrl: './looker.component.html',
  styleUrls: ['./looker.component.scss']
})
export class LookerComponent implements OnInit {

  first_url: string = "https://storage.googleapis.com/amarello-web-assets/img/graph_2.svg";
  second_url: string = "https://storage.googleapis.com/amarello-web-assets/img/graph_1.svg";

  constructor(
    private title: Title,
    private meta: Meta,
    @Inject(PLATFORM_ID) private platformId: Object
  ) { }

  ngOnInit(): void {
  }

  updateSrc(url) {   
      this.first_url = url; // <- changed here
  }


}
about 4 years ago · Juan Pablo Isaza 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