Skip to content

Instantly share code, notes, and snippets.

@jhades
Created May 12, 2016 07:55
Show Gist options
  • Save jhades/25483b615ec7c18cab06bc53f37d7102 to your computer and use it in GitHub Desktop.
Save jhades/25483b615ec7c18cab06bc53f37d7102 to your computer and use it in GitHub Desktop.
Core Directives NgIf
@Component({
selector: 'app',
template: `
<div class="toggle-panel" *ngIf="show"
[hidden]="hidden" [style.visibility]="visibility">Toggle Me</div>
<button (click)="toggleShow()">Show</button>
<button (click)="toggleHidden()">Hidden</button>
<button (click)="toggleVisible()">Visible</button>
`
})
export class App {
show = true;
hidden = false;
visibility = 'visible';
toggleShow() {
this.show = !this.show;
}
toggleHidden() {
this.hidden = !this.hidden;
}
toggleVisible() {
this.visibility = this.visibility == 'visible' ? 'hidden' : 'visible';
}
}
bootstrap(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment