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

388
Vistas
Can I use anchor tags to jump to different locations on different pages in Angular?

I'm using anchor tags in my navbar to send users to different sections on the about page. Problem is, it only works if I'm already in the about page. It doesn't jump to the specific location I want it to when I click on those links in my navbar from other pages (like for example, homepage).

This is my navbar.html:

      <mat-menu #aboutMenu="matMenu">
        <button mat-menu-item>
          <a href="/about-us#about"> About </a>
        </button>
        <button mat-menu-item>
          <a href="/about-us#token"> Token </a>
        </button>
        <button mat-menu-item>
          <a href="/about-us#team"> Team </a>
        </button>
      </mat-menu>

And this is my about.html:

    <a name="about">
      <h1>About</h1>
    </a>
     .
     .
     .
    <a name="token">
      <h2>Token Details</h2>
    </a>
     .
     .
    <a name="team">Team Members</a>
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I solved using the following code:

.html:

<a [routerLink]="'/about-us'" fragment="about" (click)="onAnchorClick()"> About </a>

.ts:

  onAnchorClick ( ) {
    this.route.fragment.subscribe ( f => {
      const element = document.querySelector ( "#" + f )
      if ( element ) element.scrollIntoView ( true )
    });
  }
over 4 years ago · Santiago Trujillo Denunciar

0

I solved it with the help of @davimargelo's answer like this:

navbar.html

        <button
          mat-menu-item
          [routerLink]="'/about-us'"
          fragment="token"
          (click)="onAnchorClick()"
          class="button__mat--menu"
        >
          <a href="/about-us#token"> Token </a>
        </button>

navbar.ts

  onAnchorClick() {
    this.route.fragment.subscribe((f) => {
      const element = document.querySelector('#' + f);
      if (element) element.scrollIntoView(true);
    });
  }

about-us.html

    <a name="token">
      <h2 id="token-details">Token Details</h2>
    </a>
over 4 years ago · Santiago Trujillo Denunciar

0

To navigate to another page on clicking a button just use angular event binding syntax.The event binding listens to the click event of the button and calls its respective method in the component.ts file. Refer link for more understanding: https://angular.io/guide/event-binding

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