2
我目前正在尝试看看,如果在Angular 2中我们可以创建动态选择器/ html标签。例如,我想要做这样的事情:Angular 2:动态选择器属性
@Component({
selector: 'my-app' + 'variableName',
template: `
<container> </container>
`,
directives: [ContainerComponet]
})
,这样我可以这样做:
<my-app + {{variableName}}> <!-- the variable name would be coming from a public variable inside my component-->
在某种程度上,我的组件的实现需要发生好几次,我知道我可以复制/粘贴我拥有的多个组件,但是我觉得必须有更智能的方法。
有一些技巧通过在运行时动态创建组件来实现类似帽子的东西。另一种可能适用于你的方法是http://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468 –
就像'完全不受支持。 Angular从不匹配动态创建内容的选择器。最近有讨论支持诸如'[someSelector] =“boolValue?true:null”'等选择器的指令。 –
感谢Gunter!我会考虑链接 – eagleEye