[英]How to add styling to the root component dom element (angular selector 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%
}
在 html 中,将如下所示:
<head>...</head>
<body>
....
<form-button>
<div class="form-button-wrapper">
<div class="content"></div>
</div>
</form-button>
....
</body>
我想为<form-button>
而不是在<div class="form-button-wrapper">
定义宽度和重量。
我怎样才能做到这一点?
是的,只需使用:host
选择器。 它使您可以访问环绕的角度元素。
//form-button.component.scss
:host {
// insert your styles here
}
.form-button-wrapper {
width: 100%;
height: 100%
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.