本文介绍了角2:如何样式组件的host元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在角2分量叫我-COMP:
I have component in Angular 2 called my-comp:
<my-comp></my-comp>
如何一个样式此组件的角2主元素?
How does one style the host element of this component in Angular 2?
在聚合物,你会用:主机的选择器。我试图在角2,但是不起作用。
In Polymer, You would use ":host" selector. I tried it in Angular 2. But it doesn't work.
:host {
display: block;
width: 100%;
height: 100%;
}
我还使用组件作为选择尝试:
I also tried using the component as selector:
my-comp {
display: block;
width: 100%;
height: 100%;
}
这两种方法似乎并不工作。
Both approaches don't seem to work.
感谢。
推荐答案
查看将实施新的模板precompilation逻辑。现在我觉得你可以做的最好的就是你的模板包装成&LT; DIV CLASS =根&GT;
和风格这个 DIV
:
Check out this issue. I think the bug will be resolved when new template precompilation logic will be implemented. For now I think the best you can do is to wrap your template into <div class="root">
and style this div
:
@Component({ ... })
@View({
template: `
<div class="root">
<h2>Hello Angular2!</h2>
<p>here is your template</p>
</div>
`,
styles: [`
.root {
background: blue;
}
`],
...
})
class SomeComponent {}
请参阅
这篇关于角2:如何样式组件的host元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!