I have an array of items, which looks like this:
nav: any = [
{
name: 'Homepage',
url: 'homepage'
internal: false
},
{
name: 'Section 1',
hash: 'section-1'
internal: true
},
];
Now I need to ouput a list of a
-elements. These should either contain a routerLink
if internal
is false – or they should become an internal anchor. I've tried:
<a class="link"
*ngFor="for item of nav"
[href]="item.internal ? '#' + item.hash : null"
[routerLink]="item.internal ? null : item.url">
{{ item.title }}
</a>
This renders homepage
correctly, but Section 1
comes out wrongly:
<a class="link" href="/homepage">Homepage</a>
<a class="link" href="/">Section 1</a>
This is what I actually want:
<a class="link" href="/homepage">Homepage</a>
<a class="link" href="#section-1">Section 1</a>
How to achieve this correctly?