Answer the question
In order to leave comments, you need to log in
How to display information from one select by selecting an option from another?
There are two "selects", one showing the years and the other showing the holidays. This is what the models look like:
holiday.model:
export class Holiday{
constructor(
...
public date?: Date,
public name?: string,
...
) { }
}
export class Year{
constructor(
public years?:number
) { }
}
<label>Года</label>
<label for="favcity">
<select id="favcity" name="select" >
<option *ngFor="let year of years" [value]="year.years" (click)="onYearSelection(year.years)">
{{year.years | int}}
</option>
</select>
</label>
<label>Праздники</label>
<label for="favcity">
<select id="favcity" name="select" >
<option *ngFor="let holiday of filteredholidays" [value]="holiday.name">
{{holiday.name}}
</option>
</select>
</label>
onYearSelection(year){
this.filteredholidays = []
this.filteredholidays = this.holidays.filter(holiday => holiday.date.getFullYear() == year);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question