How do I add a routerLink attribute programmaticaly ? inside a directive
@Input() set siteMapLeaf(caption:string)
{
let view = this.templateRef.createEmbeddedView({});
const parentNode = view.rootNodes[0];
// <a routerLink="dashBoard">Some Text</a>
const leaf = this.renderer.createElement('a');
const text = this.renderer.createText(caption);
this.renderer.appendChild(leaf, text);
this.renderer.addClass(leaf,'siteMapLeafDiv');
this.renderer.setAttribute(leaf,'routerLink','dashBoard');
this.renderer.insertBefore(parentNode,leaf, parentNode.firstChild);
this.viewContainer.insert(view);
}
is it possible ? or do I have to inject a component that deals with the routerLink ?
thanks
from yurzui
one can't add directive dynamically
<hello name="{{ name }}"></hello>
<div *siteMapLeaf="'Campaign' as item">
<a class="siteMapLeafDiv" [routerLink]="item.link">{{item.text}}</a>
</div>