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

154
Vistas
angular 4 change templateurl after if

Okay so i have a component file with a templateurl

Within that template IT is router outlet Thats Okay. Is there a way to change the component path file if Some conditions are met within the component ?

the main idea is to check if user is online , if it is show index1, else show index2.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
   if(USERISONLINE) {
     changetemplateurl to something else
   }
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Assuming that you're trying to redirect to a component if the user is already logged in. If not another component.

You can try this.

ngOnInit() {
    if(USERISONLINE) {
     this.router.navigate([app/path1]); // whatever the path configured in router if the user is online
   } else {
     this.router.navigate([app/path2]); // whatever the path configured in router if the user is not online
   }
}

Don't forget to import the router and reference it - Dependency Injection and implements part of the lifecycle hook

But, Recommended way of doing this is using router guards since this redirection happens in the OnInit life cycle of the component. But, for your approach, this answer will work

over 4 years ago · Santiago Trujillo Denunciar

0

If I understood your scenario correctly, based on login flag you need to perform two separate operation

You can use routelink if you are using hyperlinks

<li><a [routerLink]="['/Login',{Flag:'Success'}]">Dashboard</a></li>

or Component Attribute

<Login [Flag]="Success"></Login>

You will get this Flag in your component, based on that you can perform business logic inside.

over 4 years ago · Santiago Trujillo 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