I'm in need of some simple code assistance. I want to display a list of countries that correspond to a selected letter, but I'm struggling to do so dynamically at the moment. For example, if I select the letter A from a dropdown menu, I want the countries related to that letter to be displayed below the dropdown.
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options">
{{o.letter}}
</option>
</select>
<p *ngFor="let o of options">Countries are: {{ o.countries }}</p>
export class AppComponent {
selectedOption: string;
options = [
{ letter: "A", countries: ["Afghanistan", "Albania", "Argentina"] },
{ letter: "B", countries: ["Bangladesh", "Bahamas", "Bahrain"] }
]
}
If A is chosen, then Afghanistan, Albania... should be displayed. If B is chosen, then... If C is chosen, then... I also want to be able to expand the array in the future.