-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tab-set): fix default tab with routing
resolve several issues relating to setting the default tab based on url closes #2061
- Loading branch information
1 parent
094552f
commit cdc7161
Showing
7 changed files
with
42 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 5 additions & 26 deletions
31
...ects/cashmere-examples/src/lib/selected-tab-input/selected-tab-input-example.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,21 @@ | ||
import {Component, OnDestroy, OnInit} from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
import { TabChangeEvent } from '@healthcatalyst/cashmere'; | ||
import { Subject } from 'rxjs'; | ||
import { map, takeUntil } from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'hc-selected-tab-input-example', | ||
templateUrl: 'selected-tab-input-example.component.html', | ||
// TODO: delete the SCSS file if you don't need it in the example | ||
styleUrls: ['selected-tab-input-example.component.scss'] | ||
}) | ||
export class SelectedTabInputExampleComponent implements OnInit, OnDestroy { | ||
|
||
export class SelectedTabInputExampleComponent { | ||
tabSelected = new FormControl(1); | ||
currentSelected = 1; | ||
unsubscribe = new Subject<void>(); | ||
currentSelected = 2; | ||
|
||
selectionChanged(event: TabChangeEvent): void { | ||
this.tabSelected.setValue(event.index); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.tabSelected.valueChanges.pipe( | ||
map(value => { | ||
if (value) { | ||
return Number(value); | ||
} | ||
|
||
return 0; | ||
}), | ||
takeUntil(this.unsubscribe) | ||
).subscribe(value => { | ||
this.currentSelected = value; | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.unsubscribe.next(); | ||
this.unsubscribe.complete(); | ||
controlChanged(): void { | ||
this.currentSelected = Number(this.tabSelected.value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters