以下代码是下拉列表中的OnChange事件下拉列表。 $ event.target.value只给我一个新值(在选择之后)。如何使用onChanges事件获得之前的值(选择前的值)。
<select class="form-control selectpicker selector" name="selectedQuestion1" [ngModel]="selectedQuestion1" (Onchange)="filterSecurityQuestions($event.target.value,0)">
<option [value]="0" disabled selected>Select Secuirty Question1</option>
<option *ngFor="let securityQuestion of securityQuestions[0]" [value]="securityQuestion.SecurityQuestionID" >
{{securityQuestion.Question}}
</option>
</select> <br />
<div>
<input type="text" class="form-control" id="first_name" name="securityAnswer1" placeholder="Your first security answer">
</div>
filterSecurityQuestions(questionNo: number, securityQtnDropdownNo: number) {
// I want previous value of dropdown here.
}
答案 0 :(得分:1)
您可以保留一个将保存旧值的属性,例如:
<强> HTML 强>
<select #select id="pageSize" [ngModel]="myValue" (ngModelChange)="select.value = onChange($event)">
<option value="1">value1</option>
<option value="2">value2</option>
<option value="3">value3</option>
</select>
<强>打字稿强>
myValue = 1;
oldValue=1
onChange(event) {
const response = window.confirm("Are you sure you want change the page size? Your edits will be lost?");
if (response) {
this.myValue = event;
this.oldValue = event;
}
else{
this.myValue = this.oldValue;
}
console.log(this.myValue)
console.log(this.oldValue)
return this.myValue;
}