enum Currency {
USD = 'US Dollar',
MYR = 'Malaysian Ringgit',
SGD = 'Singapore Dollar',
INR = 'Indian Rupee',
JPY = 'Japanese Yen'
}
在Angular的Html中引用時可用以下方法:
<select [(ngModel)]="selectedCurrency">
<option
*ngFor="let currency of currencies | keyvalue"
value="{{currency.key}}">
{{currency.value}}
</option>
</select>
值的動態綁定(例如要在AppComponent中作綁定):
export class AppComponent {
currencies = Currency;
selectedCurrency: Currency;
}
Morse 2020/08/02
沒有留言:
張貼留言