In an Angular 2 application I am writing, I have a select element that is bound to a field in the controller via [(ngModel)]:
<select [(ngModel)]="dateInfo.year" class="form-control">
<option *ngFor="let year of getYearList()" [value]="year">{{year}}</option>
</select>
dateInfo is a property in the controller that refers to a DateInfo object contained in a service called DateService:
@Injectable()
export class DateService {
public dateInfo: DateInfo = {
year: 2016
}
}
The DateInfo object itself is a simple Typescript interface that just stores the year:
export interface DateInfo {
year: number
}
The reason I am using this interface is to propagate changes to year to all components that use DateService, as per the first answer to this question.
For some reason, when the model is changed from the select element, the whole application freezes (tested in Chrome and Edge). I have made a plunker to illustrate the problem here.
Thanks in advance!