import { Component } from '@angular/core' ; import { Router } from '@angular/router' ; import { I18nService } from 'i18n/i18n.service' ; import { EndangeredLanguage , EndangeredLanguageService } from 'services/endangered-language' ; import { AppRoutes } from 'app/routes' ; @ Component ( { selector : 'app-list-languages' , templateUrl : './list-languages.html' , styleUrls : [ './list-languages.scss' ] } ) export class ListLanguagesPageComponent { public get endangeredLanguages ( ) : EndangeredLanguage [ ] { return this . endangeredLanguageService . languages ; } private _currentLanguageIndex = 0 ; public get currentLanguageIndex ( ) { return this . _currentLanguageIndex ; } public set currentLanguageIndex ( value ) { this . _currentLanguageIndex = value ; const state = history . state ; state . languageIndex = value ; history . replaceState ( state , '' ) ; } constructor ( private router , private i18nService , private endangeredLanguageService ) { this . _currentLanguageIndex = history . state . languageIndex || 0 ; } onLanguageChanged ( index ) { this . currentLanguageIndex = index ; } onCloseClick ( ev ) { ev . stopPropagation ( ) ; history . back ( ) ; } onLanguageClick ( code ) { this . router . navigate ( [ AppRoutes . ListLanguages , code ] ) ; } }