Skip to content

Instantly share code, notes, and snippets.

@pietmichal
Last active January 8, 2017 20:58
Show Gist options
  • Select an option

  • Save pietmichal/77dd03f303a5f575b6e2583efba1f1d5 to your computer and use it in GitHub Desktop.

Select an option

Save pietmichal/77dd03f303a5f575b6e2583efba1f1d5 to your computer and use it in GitHub Desktop.

Revisions

  1. Michał Pietraszko revised this gist Jan 8, 2017. 2 changed files with 8 additions and 8 deletions.
    8 changes: 4 additions & 4 deletions tabs.component-fragment.ts
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    onTabClick(tabName: string) {
    this.currentTab = this.tabList.find(t => t.name === tabName);
    onTabClick(tab: TabComponent) {
    this.currentTab = tab;
    }

    isSelected(tabName: string) {
    return this.currentTab.name === tabName;
    isSelected(tab: TabComponent) {
    return this.currentTab.name === tab.name;
    }
    8 changes: 4 additions & 4 deletions tabs.component.html
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    <span
    *ngFor="let t of tabList"
    [ngClass]="{selected: isSelected(t.name) }"
    (click)="onTabClick(t.name)"
    *ngFor="let tab of tabList"
    [ngClass]="{selected: isSelected(tab)}"
    (click)="onTabClick(tab)"
    >
    {{t.name}}
    {{tab.name}}
    </span>
    <div><template [ngTemplateOutlet]="currentTab.templateRef"></template></div>
  2. Michał Pietraszko created this gist Jan 8, 2017.
    7 changes: 7 additions & 0 deletions tabs.component-fragment.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    onTabClick(tabName: string) {
    this.currentTab = this.tabList.find(t => t.name === tabName);
    }

    isSelected(tabName: string) {
    return this.currentTab.name === tabName;
    }
    8 changes: 8 additions & 0 deletions tabs.component.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <span
    *ngFor="let t of tabList"
    [ngClass]="{selected: isSelected(t.name) }"
    (click)="onTabClick(t.name)"
    >
    {{t.name}}
    </span>
    <div><template [ngTemplateOutlet]="currentTab.templateRef"></template></div>