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

286
Visualizações
Angular *ngIf check if element currently getting shown on page or not

*ngIf check if element currently getting shown on page or not.

I have two sibling component. Component A having a some text value say 'SOME_TEXT' Now in html of Component B, I need check for span element.

If 'SOME_TEXT' is getting shown currently on page/app then *ngIf should be false. Meaning span tag in component B should NOT be shown.

enter image description here

Has anyone encountered this. ?

Thanks.

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

0

I'm not sure about the question, but I think you could use DOM to get the element in component A at somewhere of component B's script. For example, inside component B's ngOnInit get some value from

document.getElementById("id in A html")

or

Use Service and power of Observable

@Injectable({
  providedIn: 'root'
})
export class TextService {

  textObserver: Observer<string>|undefined
  text: Observable<string> = new Observable()

  updateText(val: string) {
    
    if (!this.textObserver) {
      this.text = new Observable((observer: Observer<string>) => {
        this.textObserver = observer
        this.textObserver.next(val)
      })
      this.text.subscribe()
      return;
    }
    this.textObserver?.next(val)
  }

}

In somewhere of component A you can call updateText to set text and in component B you can do this.textService.text.subscribe(text => // your code) to get text and use in html view

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