如何给 angular 组件添加样式? (每隔一个元素)

How to add styles to angular component? (every second element)

我对向 Angular 组件添加样式有疑问。 例如,我希望列表中的每一秒 angular 组件都具有红色背景色。 我怎样才能实现它?

我尝试了很多不同的东西 - 它似乎被添加到 HTML 但不起作用。

<ang-component class="someClass" />
<ang-component class="someClass" />

我尝试在父组件样式中设置它

ang-component:nth-child(odd) {
 background-color: red;
}

但它不起作用。检查时出现,但没有明显效果

编辑:代码 - 显示示例

<form [formGroup]="form" class="someParentClass" (ngSubmit)="onUpdateForm()" >
    <item></item>
    <hr />
    <item></item>
    <item></item>
<hr />
<div id="btn-save-section">
    <button class="cancel-btn" type="button">Cancel</button>
    <button class="update-btn" type="button">Update</button>
</div>

我希望项目组件发生变化 - 所以每秒的背景颜色都应该是红色

ang-component:nth-child(odd) > * {
 background-color: red;
}

因为您的组件根元素可能只是一个宽度为 0 高度为 0 的容器