How can I conditionally use either [href] or [routerLink] on an anchor?

Discussão em 'Angular' iniciado por Toolkit, Novembro 13, 2024.

  1. Toolkit

    Toolkit Guest

    I need for the same anchor link to be pointed conditionally locally or to external resource. I tried

    <a [href]="outside?externalUrl:null" [routerLink]="outside?[]:['/route',id]" >test</a>


    But it doesn't work. I don't get any errors, but it points to the same local page and ignores the external URL. Any ideas?

    Another option would be to construct the link, but I can't find any docs how to access routerLink inside a service

    Edit: I know I can clone the whole link with *ngIf but I don't want to do it, my link contains a video tag with a buch of options

    Continue reading...

Compartilhe esta Página