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}}
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" } ]; }