1
ルータリンク属性をプログラム的に追加するにはどうすればよいですか?内訳角度2 - 構造指令 - ルータリンクを挿入する方法
@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
例がありますか?私はhow.Tanksを参照してくださいない – phil1234
https://stackblitz.com/edit/angular-etlype?file=app/app.component.html – yurzui