我正在尝试根据我的输入复选框将 css 添加到我的 div
<div class="pvreveal" [style]="ShowHideSection ? 'overflow:scroll;height:483px':''" >
<input id="isDelivery" type="checkbox" [(ngModel)]="ShowHideSection " />
</div
如何实现
最佳答案
通过使用[ngClass]
。我不太喜欢内联样式
//CSS
.myClass{overflow:scroll;height:483px}
//组件
export class MyComponent {
public ShowHideSection : boolean = true;
}
//HTML
<div class="pvreveal" [ngClass]="{'myClass' : ShowHideSection}" >
<input id="isDelivery" type="checkbox" [(ngModel)]="ShowHideSection " />
</div>
关于html - 如何根据条件添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59673490/