我试图创建一个使用角度2.一个非常简单的例子一个表单生成如下:NG-含量的选择变量绑定
this.fields = [{name: 'Name', type: 'text'}, {name: 'Age', type: 'number'}];
但我也想支持像自定义元素:
this.fields = [
{name: 'Name', type: text},
{name: 'Age', type: 'custom', customid: 'Ctl1'},
{name: 'Whatever', type: 'custom', customid: 'Ctl2'}
];
// template:
<super-form [fields]="fields">
<Ctl1><input type="number" ...><Ctl1>
<Ctl2><whaterver-control ...><Ctl2>
</super-form>
在我的表单生成组件然后我有类似:
<div *ngFor="let f of fields">
<div [ngSwitch]="f.type">
<span *ngSwitchWhen="'custom'">
<ng-content select="f.customid"></ng-content>
</span>
</div>
</div>
但考虑到我在这里这显然不不行。这是一个ng2限制吗?如果是这样,我想我可以硬编码说5可选内容元素,并检查他们是否指定,并没有动态选择,但这是一个黑客。
干杯
是的..试过了,选择被忽略 – gatapia
@gatapia对不起,它似乎'ng-content'只用于静态投影。 [检查这个问题](https://github.com/angular/angular/issues/8563) – Abdulrahman
谢谢我刚刚发现,也。修改你的答案,并将其标记为正确。 – gatapia