You can use a directive *ngIfor property to do this hidden.
Note the difference:
*ngIf Deletes and recreates the item:
, ngIf, , DOM, DOM.
angular `s :
show/hide, , . ; NgIf . , .
:
@Component({
selector: 'my-app',
template: `
<b>Using *ngIf:</b>
<div *ngIf="!isOn">Light Off</div>
<div *ngIf="isOn">Light On</div>
<br />
<b>Using [hidden]:</b>
<div [hidden]="isOn">Light Off</div>
<div [hidden]="!isOn">Light On</div>
<br />
<button (click)="setState()">{{ getButtonText() }}</button>
`
})
export class AppComponent {
private isOn: boolean = false;
getButtonText(): string {
return `Switch ${ this.isOn ? 'Off' : 'On' }`;
}
setState(): void {
this.isOn = !this.isOn;
}
}
Plunker: http://plnkr.co/edit/7b1eWgSHiM1QV6vDUAB0
[hidden], : http://angularjs.blogspot.com.br/2016/04/5-rookie-mistakes-to-avoid-with-angular.html
, .