javascript - 如何为根组件 dom 元素添加样式(角度选择器组件)
问题描述
我有以下组件:
// 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%
}
推荐阅读
- javascript - 使用 splice() 删除后将所有项目带回数组中
- batch-file - 使用 PSEXEC cmd /c 远程清除凭据时出错
- css - CSS中的不透明度淡入问题
- python - 使用 Python 从 csv 构建字典列表
- android - how to set image view source dynamically?
- firebase - 部署时混合内容错误
- laravel - Laravel 测试。断言准确的 JSON 结构
- c# - 数据网格不更新索引
- c - 如何通过指针结构变量访问结构内的指针成员?
- excel - Excel-防止单元格引用在这些引用中的数据移动时发生变化