简体   繁体   English

如何为根组件dom元素(角度选择器组件)添加样式

[英]How to add styling to the root component dom element (angular selector component)

I have the following component:我有以下组件:

// Typescript
@Component({
    selector: 'form-button',
    templateUrl: './form-button.component.html',
    styleUrls: ['./form-button.component.scss']
})
export class FormButtonComponent {}

//form-button.component.html
<div class="form-button-wrapper">
    <div class="content"></div>
</div>

//form-button.component.scss
.form-button-wrapper {
    width: 100%;
    height: 100%
}

In the html, will looks like this:在 html 中,将如下所示:

<head>...</head>
<body>
    ....
    <form-button>
         <div class="form-button-wrapper">
             <div class="content"></div>
         </div>
    </form-button>
    ....
</body>

I want t defined a width and weight to the <form-button> instead of in the <div class="form-button-wrapper"> .我想为<form-button>而不是在<div class="form-button-wrapper">定义宽度和重量。

How can I do that?我怎样才能做到这一点?

Yes, just use the :host selector.是的,只需使用:host选择器。 It gives you access to the wrapping angular element.它使您可以访问环绕的角度元素。

//form-button.component.scss

:host {
 // insert your styles here
}

.form-button-wrapper {
    width: 100%;
    height: 100%
}

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

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