Angular 2 - 结构指令 - 如何插入路由器 link

Angular 2 - Structural Directive - How to insert a router link

如何以编程方式添加 routerLink 属性?在指令中

@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);
}

可能吗? 还是我必须注入处理 routerLink 的组件?

谢谢

来自yurzui

不能动态添加指令

<hello name="{{ name }}"></hello>
<div *siteMapLeaf="'Campaign' as item">
  <a class="siteMapLeafDiv" [routerLink]="item.link">{{item.text}}</a>
</div>