So I have a very simple scenario where there's a confirmation popup to be shown on dropdown change. If the user chooses to cancel, I need to revert the dropdown value to old one. I think I'm doing correctly and even in the DOM, value of ngModel bound with select is reflecting. But somehow it's not reverting the selected value in display. Here's my code
<select style="display: inline-block;width: 20%" class="form-control"
name="selectedClientVersion"
(change)="selectedCurrentVersion($event.target.value)"
[(ngModel)]="selectedClientVersion">
<option *ngFor="let i of clientVersions"
[selected]="i == 'selectedClientVersion' ">{{i}}</option>
</select>
selectedClientVersion='version1';
prevSelectedClientVersion='version1';
clientVersions=['version1', 'version2', 'version3'];
selectedCurrentVersion(val){
var r = confirm("Do you really want to chnage?");
if (r == true) {
this.prevSelectedClientVersion= this.selectedClientVersion= val;
} else {
this.selectedClientVersion=this.prevSelectedClientVersion;
//return false;
}
}
P.S I tried ngModelChange too in place of change.
Update: I have already searched on stackOverflow for similar answer and found none of the scenario handles this case where there's an involvement of confirmation popup and the values have to be reverted based on that in Angular 2
UPDATE2: This is what I want to do, albeit in angular 2: Reset back to previous option on Select field if js Confirm returns false http://jsfiddle.net/CZ8F9/

