有人能快速告诉我如何在Angular中使用下面的代码吗?有没有等价物,或者我可以直接使用它?
document.getElementById("overlay").style.display = "none";
发布于 2018-07-10 09:04:08
在HTML中使用*ngIf:
<div *ngIf="yourBooleanVariable">...</div>
现在,如果在component.ts中将“div”设置为false,则不会呈现该div。如果将该值更改为true,则将显示该div。
如果只想更改样式,请使用NgStyle。
示例:
<div [ngStyle]="{'background-color': yourVariable === 'condition' ? 'color1' : 'color2' }"></<div>
这称为三元运算符,其含义如下:
如果'yourVariable‘= 'condition',则背景颜色设置为"color1“,否则背景颜色将设置为"color2”
https://stackoverflow.com/questions/51250816
复制相似问题