Dynamically setting an a-tag's target and rel properties

Given <a href.bind="msg.url"> is it possible to dynamically add a target and rel attribute when e.g. msg.openInNewPage is true? I’ve tried this

<a href.bind="msg.url" 
   target.bind="${msg.openInNewPage ? '_blank' : '_self'}"
   rel.bind="${msg.openInNewPage ? 'noopener noreferrer' : ''}"
>...</a>

but that didn’t work.

Any pointers, tips, etc?

If this is not typo, I think you are mixing the .bind with string interpolation. I think you would be fine with simply:

<a href.bind="msg.url" 
   target.bind="msg.openInNewPage ? '_blank' : '_self'"
   rel.bind="msg.openInNewPage ? 'noopener noreferrer' : ''"
>...</a>
2 Likes

You’re probably right. I’m not doing Aurelia work often enough, so I tend to forget these things.