DEV Community

loading...

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

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:

  • [attr.target]="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 [attr.target] for best results :)

Discussion (0)

Forem Open with the Forem app