DEV Community


Angular - quick tip of the day: External links - "target" attribute

mmanista profile image Maciej Manista ・1 min read

Let’s say we have a link and we want to open it in either new tab or same tab, depending on the value of a variable.
Let’s assume openInNewTab variable is false:

  • []="openInNewTab ? '_blank' : null" - works fine, produces no target attribute

  • [target]="openInNewTab ? '_blank' : null" - produces target="null" as an attribute, which still opens the link in a new tab, just the same as if you used _blank

TL;DR: use [] for best results :)

Discussion (0)

Forem Open with the Forem app