I have an ng-for loop outputting my menu class dynamically. The first time the page is loaded, the ng-reflect-router-link and ng-reflect-href are set correctly. The issue is after on of the links are clicked, all ng-reflect-hrefs change to whatever link was clicked.
routes.ts
import { RouterConfig } from '@angular/router';
import { Home } from './views/home/home';
import { FetchData } from './components/fetch-data/fetch-data';
import { Counter } from './components/counter/counter';
export const routes: RouterConfig = [
{ path: 'home', component: Home },
{ path: 'counter', component: Counter },
{ path: 'fetch-data', component: FetchData }
];
sidebar-menu.ts
import * as ng from '@angular/core';
import {ROUTER_DIRECTIVES, Http} from './index.ts'
@ng.Component({
selector: 'sidebar-menu',
template: require('./sidebar-menu.html'),
directives: [...ROUTER_DIRECTIVES]
})
export class SidebarMenu {
public menus: Menu[];
constructor(http: Http) {
//todo - put this in a service.ts
http.get('/api/Menu/Menus').subscribe(result => {
this.menus = result.json();
});
}
}
menu.ts
interface Menu {
name: string;
decorator: string;
}
sidebar-menu.html
<ul>
<li *ngFor="#menu of menus" >
<a [routerLink]="menu.name">
<span class='glyphicon glyphicon-th-list {{menu.decorator}}'></span> {{menu.name}}</a>
/li>
</ul>
After I click a link (couter is the link I clicked in the example below), this is what the html looks like:
<ul class="nav navbar-sidebar">
<!--template bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object]"
}--><li>
<a ng-reflect-router-link="counter" ng-reflect-href="/counter" href="/counter">
<span ng-reflect-class-name="glyphicon glyphicon-th-list " class="glyphicon glyphicon-th-list " classname="glyphicon glyphicon-th-list "></span> counter
</a>
</li><li>
<a ng-reflect-router-link="fetch-data" ng-reflect-href="/counter" href="/counter">
<span ng-reflect-class-name="glyphicon glyphicon-th-list " class="glyphicon glyphicon-th-list " classname="glyphicon glyphicon-th-list "></span> fetch-data
</a>
</li>
</ul>
My project is set up very similar to Dynamic routerLink value from ngFor item giving error "Got interpolation ({{}}) where expression was expected". but my links are displaying correctly, unlike that post.