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

163
Vistas
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 Respuestas
Responde la pregunta

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 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