feat(HotelItem): update currency display logic and options

This commit is contained in:
Jan Gleytenhoover 2024-09-17 08:23:33 +02:00
parent f96a09abc4
commit f575d73b3a
Signed by: jank
GPG Key ID: B267751B8AE29EFE
2 changed files with 19 additions and 5 deletions

@ -1,9 +1,9 @@
<p>Name: {{hotel.hotelName}}</p> <p>Name: {{hotel.hotelName}}</p>
<p>Description: {{hotel.description}}</p> <p>Description: {{hotel.description}}</p>
<p>Price: {{hotel.price | currency : "EUR" : "symbol" : "2.2-2" : "de-DE"}}</p> <p>Price: {{hotel.price | currency : getCurrencyCode(selectedLanguage) : "symbol" : "2.2-2" : selectedLanguage}}</p>
<select [ngModel]="selectedLanguage" (ngModelChange)="languageChange($event)"> <select [ngModel]="selectedLanguage" (ngModelChange)="languageChange($event)">
@for (lang of langs; track lang.lang) { @for (lang of langs; track lang.lang) {
<option value="{{lang.lang}}">{{lang.lang}}</option> <option value="{{lang.code}}" [selected]="lang.lang === 'de'">{{lang.lang}}</option>
} }
</select> </select>
<img src="{{hotel.imageUrl}}" alt="Hotel"> <img src="{{hotel.imageUrl}}" alt="Hotel">

@ -20,18 +20,32 @@ export class HotelItem {
console.log(this.selectedLanguage); 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 = [ public langs = [
{ {
"lang": "en", "lang": "en",
"code": "en-US" "code": "en-US",
"currency": "USD"
}, },
{ {
"lang": "cn", "lang": "cn",
"code": "cn-CN" "code": "cn-CN",
"currency": "CNY"
}, },
{ {
"lang": "de", "lang": "de",
"code": "de-DE" "code": "de-DE",
"currency": "EUR"
} }
]; ];
} }