【发布时间】:2017-05-24 10:58:57
【问题描述】:
我一周前开始学习 Angular2 和最新的 angular4,现在我需要创建一个自定义结构指令来显示其中的内容。
解释:我有一个数组的元素一对字符串让我们调用数组标题的n个元素的第一个元素和第二个描述 这是结果https://ibb.co/i23Dxa
(数组来自后端,我是通过mock数组文件来模拟的)
现在,如果我调用我需要创建的结构指令,我希望它显示我将在该调用下编写的内容
示例:
<ng-template aulos-configuration-item-toolbar>
<button (click)="click()">just click</button>
</ng-template>
这应该只呈现我在标签之间写的按钮,现在,我有这个:
import { Directive, Input, TemplateRef, ViewContainerRef } from "@angular/core";
@Directive({
selector: "[aulos-configuration-item-toolbar]",
})
export class AulosConfigurationItemToolbar {
public templateRef: TemplateRef<any>;
constructor(templateRef: TemplateRef<any>) {
this.templateRef = templateRef;
}
}
谁能更好地向我解释如何进行?非常感谢。
【问题讨论】:
-
你读过
吗?