|
| 1 | +import {Component, ViewEncapsulation} from '@angular/core'; |
| 2 | +import {Router} from '@angular/router'; |
| 3 | +import {Observable} from 'rxjs/Observable'; |
| 4 | + |
| 5 | +@Component({ |
| 6 | + moduleId: module.id, |
| 7 | + selector: 'tabs-demo', |
| 8 | + templateUrl: 'tabs-demo.html', |
| 9 | + styleUrls: ['tabs-demo.css'], |
| 10 | + encapsulation: ViewEncapsulation.None, |
| 11 | +}) |
| 12 | +export class TabsDemo { |
| 13 | + tabLinks = [ |
| 14 | + { label: 'Sun', link: 'sunny-tab'}, |
| 15 | + { label: 'Rain', link: 'rainy-tab'}, |
| 16 | + { label: 'Fog', link: 'foggy-tab'}, |
| 17 | + ]; |
| 18 | + activeLinkIndex = 0; |
| 19 | + |
| 20 | + tabs = [ |
| 21 | + { label: 'Tab One', content: 'This is the body of the first tab' }, |
| 22 | + { label: 'Tab Two', content: 'This is the body of the second tab' }, |
| 23 | + { label: 'Tab Three', content: 'This is the body of the third tab' }, |
| 24 | + ]; |
| 25 | + |
| 26 | + asyncTabs: Observable<any>; |
| 27 | + |
| 28 | + constructor(private router: Router) { |
| 29 | + this.asyncTabs = Observable.create((observer: any) => { |
| 30 | + setTimeout(() => { |
| 31 | + observer.next(this.tabs); |
| 32 | + }, 1000); |
| 33 | + }); |
| 34 | + |
| 35 | + // Initialize the index by checking if a tab link is contained in the url. |
| 36 | + // This is not an ideal check and can be removed if routerLink exposes if it is active. |
| 37 | + // https://github.com/angular/angular/pull/12525 |
| 38 | + this.activeLinkIndex = |
| 39 | + this.tabLinks.findIndex(routedTab => router.url.indexOf(routedTab.link) != -1); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +@Component({ |
| 45 | + moduleId: module.id, |
| 46 | + selector: 'sunny-routed-content', |
| 47 | + template: 'This is the routed body of the sunny tab.', |
| 48 | +}) |
| 49 | +export class SunnyTabContent {} |
| 50 | + |
| 51 | + |
| 52 | +@Component({ |
| 53 | + moduleId: module.id, |
| 54 | + selector: 'rainy-routed-content', |
| 55 | + template: 'This is the routed body of the rainy tab.', |
| 56 | +}) |
| 57 | +export class RainyTabContent {} |
| 58 | + |
| 59 | + |
| 60 | +@Component({ |
| 61 | + moduleId: module.id, |
| 62 | + selector: 'foggy-routed-content', |
| 63 | + template: 'This is the routed body of the foggy tab.', |
| 64 | +}) |
| 65 | +export class FoggyTabContent {} |
0 commit comments