简体   繁体   English

将CSS类应用于Component标签

[英]Apply CSS Class to Component tag

I have the angular component (simplified version): 我有角组件(简化版):

export class HeaderMainComponent { }

With the HTML: 使用HTML:

<header>

  <nav>
    <li>Link 1</li>
    <li>Link 2</li>
  </nav>

</header>

And I use it as follows: 我使用它如下:

<header-main class="dark"></header-main>

How to apply dark css class of header-main to header tag? 如何将header-main的dark CSS类应用于header标签?

<header class="dark">

Is this possible without using a variable in the component? 如果不在组件中使用变量,是否可以做到这一点?

<header-main [classes]="'dark other-class'"></header-main>

In header-main.ts: 在header-main.ts中:

@Input('classes') classes: string;

In header-main.html: 在header-main.html中:

<header class="{{classes}}"></header>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM