-import { Component, ViewChild } from '@angular/core'
-import { ModalDirective } from 'ngx-bootstrap/modal'
+import { Component, ElementRef, ViewChild } from '@angular/core'
import { I18N_LOCALES } from '../../../../shared'
+import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
+import { sortBy } from '@app/shared/misc/utils'
@Component({
selector: 'my-language-chooser',
styleUrls: [ './language-chooser.component.scss' ]
})
export class LanguageChooserComponent {
- @ViewChild('modal') modal: ModalDirective
+ @ViewChild('modal') modal: ElementRef
- languages: { [ id: string ]: string }[] = []
+ languages: { id: string, label: string }[] = []
- constructor () {
- this.languages = Object.keys(I18N_LOCALES)
- .map(k => ({ id: k, label: I18N_LOCALES[k] }))
- }
+ constructor (private modalService: NgbModal) {
+ const l = Object.keys(I18N_LOCALES)
+ .map(k => ({ id: k, label: I18N_LOCALES[k] }))
- show () {
- this.modal.show()
+ this.languages = sortBy(l, 'label')
}
- hide () {
- this.modal.hide()
+ show () {
+ this.modalService.open(this.modal)
}
buildLanguageLink (lang: { id: string }) {