【发布时间】:2016-08-08 22:07:16
【问题描述】:
是否可以使用输入变量设置 angular2 组件的模板 url?下面的解决方案不起作用,因为直到组件详细信息下方才定义 step。但我很好奇这样的事情是否可行?
import { Component, Input } from '@angular/core';
@Component({
selector: 'demo',
templateUrl: step;
})
export class demoComponent {
@Input()
step: string;
}
然后这样称呼它:
<demo [step]="path/to/template"></demo>
【问题讨论】:
-
这样做的目的是什么?
-
不,这行不通。它在编译时用于制作捆绑包,然后
step将不会被定义。 -
@Harangue 好吧,我正在编写一个教程应用程序,并且每个步骤都有大量已解析的 git diff 文件。我希望能够引用
<codestep [step]="2.1">标记并显示正确的静态 html(渲染代码 sn-p)。但是,我希望所有 sn-ps 都执行一些逻辑。 -
@ritz078 有没有类似的东西,例如只有一个带有 1 个数据绑定的空模板,然后将所有静态 html 传递给那个?
标签: angular angular2-template angular2-components