ngModelChangeのこのサンプル例:
app.component.html
<p-dropdown [options]="cities" [(ngModel)]="selectedCity" (ngModelChange)="onSelectType($event)"></p-dropdown>
app.component.ts
import { SelectItem } from 'primeng/primeng';
export class AppComponent {
cities: SelectItem[];
selectedCity: any;
previousVal: any;
currentVal: any;
constructor() {
this.cities = [{
"label": "London",
"value": "london"
}, {
"label": "USA",
"value": "usa"
}];
}
onSelectType(event) {
if(event) {
this.previousVal = this.currentVal;
this.currentVal = event;
}
console.log('this.previousVal', this.previousVal);
console.log('this.currentVal', this.currentVal);
}
}
app.module.ts
import { DropdownModule } from 'primeng/primeng';
imports: [ DropdownModule ]
溶液が使用されます。ngModelChange;
ウィンドウ変数として格納することはオプションです。グローバル変数js varにするためです。それは最も簡単な解決策になります – Deckerz
私は以前の値と選択された値を期待どおりに答えを投稿しました。役に立ったと思う。 – Chandru
はい。実際、ngModelChangeはこれを私が探していた答えにしました。ありがとう。 –