From f575d73b3a6958f4314fd4d9e4282f27ad78c369 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Tue, 17 Sep 2024 08:23:33 +0200 Subject: [PATCH] feat(HotelItem): update currency display logic and options --- src/app/HotelItem/HotelItem.component.html | 4 ++-- src/app/HotelItem/HotelItem.component.ts | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/HotelItem/HotelItem.component.html b/src/app/HotelItem/HotelItem.component.html index 6d830d3..018aba5 100644 --- a/src/app/HotelItem/HotelItem.component.html +++ b/src/app/HotelItem/HotelItem.component.html @@ -1,9 +1,9 @@

Name: {{hotel.hotelName}}

Description: {{hotel.description}}

-

Price: {{hotel.price | currency : "EUR" : "symbol" : "2.2-2" : "de-DE"}}

+

Price: {{hotel.price | currency : getCurrencyCode(selectedLanguage) : "symbol" : "2.2-2" : selectedLanguage}}

Hotel diff --git a/src/app/HotelItem/HotelItem.component.ts b/src/app/HotelItem/HotelItem.component.ts index 163edf9..a0f14a7 100644 --- a/src/app/HotelItem/HotelItem.component.ts +++ b/src/app/HotelItem/HotelItem.component.ts @@ -20,18 +20,32 @@ export class HotelItem { console.log(this.selectedLanguage); } + public getCurrencyCode(langCode: string | undefined): string { + if (!langCode) return ''; + + for (let language of this.langs) { + if (language.code === langCode) { + return language.currency; + } + } + return ''; + } + public langs = [ { "lang": "en", - "code": "en-US" + "code": "en-US", + "currency": "USD" }, { "lang": "cn", - "code": "cn-CN" + "code": "cn-CN", + "currency": "CNY" }, { "lang": "de", - "code": "de-DE" + "code": "de-DE", + "currency": "EUR" } ]; }