说我检查它和表达,那么这两个不一样吗?
<div *ngIf="expression">{{val}}</div> <div [hidden]="!expression">{{val}}</div>
ngIf
is a structural directive,它创建/销毁DOM内的内容.第二个语句只是用css隐藏/显示内容,即向元素的样式添加/删除display:none.
What are structural directives?
Structural directives are responsible for HTML layout. They shape or
reshape the DOM’s structure,typically by adding,removing,or
manipulating elements.
在第一种情况下,如果表达式为false,则不会创建div和它的内容.在第二种情况下,div和内容总是被创建,但如果表达式为false则它们不可见.