我有一个元素列表,但我想显示其中的一些,所以我使用这个代码
[style.display]="!student.selected?'none':'block'"
但是,当我检查元素时,我可以看到它们,所以我的问题是如何用安全的东西来改变它?
您可以在模板中使用* ngIf结构指令(https://angular.io/guide/structural-directives)。所以在你的情况下,component.html将包含:
<div *ngIf="student.selected"></div>
如果学生存在,那将显示div元素。