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

162
Visualizações
ngIf condition in template not working while refresh, it's redirecting to homepage

I am working on Angular 7, and I am rendering a <div> ... </div> based on multiple values, these values I declared in the .ts file as : Boolean = false; the values will update in ngOnInit, but for my condition, it's keep redirecting back to the homepage while refreshing or first navigation to the page,

here my template

<div (click)="audioToggleSearchDropdown($event)" class="search-blk" id="audio-search" *ngIf="audioSearchKey || radioSearchKey || podcastSearchKey ">
            <input class="searchboxEvent" (keypress)="audioeventHandler($event)" #suggestbox id="search-audio-search"
              [formControl]="audioSearchContnet" [(ngModel)]="audioSearchValue"
              placeholder="{{ 'HEADER.AUDIO_SEARCH_PLACEHOLDER' | translate }}" />
 </div>

And my .ts file I declared the keys audioSearchKey , radioSearchKey podcastSearchKey as false,

audioSearchKey: Boolean = false;
radioSearchKey : Boolean = false;
podcastSearchKey : Boolean = false;

And in ngOnInit() I put a function to validate URL , and the function like,

if( url === "audio" || url === "search") {
  this.audioSearchKey = false;
  this.radioSearchKey = false;
  this.podcastSearchKey = false;
}else if (audioUrl.includes(url)) {
  this.audioSearchKey = true;
  this.radioSearchKey = false;
  this.podcastSearchKey = false;
} else if(radioUrl.includes(url)){
  this.audioSearchKey = false;
  this.radioSearchKey = true;
  this.podcastSearchKey = false;
} else if(podcastUrl.includes(url)){
  this.audioSearchKey = false;
  this.radioSearchKey = false;
  this.podcastSearchKey = true;
} else{
  this.audioSearchKey = false;
  this.radioSearchKey = false;
  this.podcastSearchKey = false;
}

After adding these, my existing page keeps redirecting to the homepage while clicking from a link and navigating to the page and while each refreshes. If am removing the HTML part with ngIf the rest of the functionalities and page working fine if anyone please suggest what error exactly it is?

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

0

Setting values to false that may be updated to true with ngOnInit is almost the same as setting them to true in your TS file. ngOnInit happens before the first DOM paint, you may want to try putting that update in ngAfterViewInit()

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