Looking for assistance with implementing a simple HTML select dropdown in Angular2 (TS) using the code below:
<select id="pageSize" (change)="onPageSizeChanged($event, pagination.pageSize)">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
</select>
The variable pagination.pageSize
stores the previously selected value. When this changes, I want to prompt the user with a dialog box and wait for their response. If they click cancel, I need to revert back to the previous selection.
onPageSizeChanged(event, oldValue) {
const response = window.confirm("Are you sure you want change the page size? Your edits will be lost?");
if (response) {
//... some code ...
} else {
//... here I want to revert the selection to previously selected option
}
}
I have tried various approaches but haven't had any success yet.
Please assist, as I am struggling with what should be a straightforward task. Perhaps I am missing something obvious.
Attempted Solution #1 - Not Working (Plunk - https://embed.plnkr.co/ILi12O/)
<select id="pageSize" [ngModel]="pageSize" (ngModelChange)="onPageSizeChanged($event, pagination.pageSize)">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
</select>
onPageSizeChanged(event, oldValue) {
const response = window.confirm("Are you sure you want change the page size? Your edits will be lost?");
if (response) { //go ahead so something }
else { this.pageSize = oldValue; }
}