event onchange mat-option in mat-select by arrows in angular
getCities(item: any) {
this.cities = [];
for (let element of item.states) {
this.cities.push(element);
}
}
_getCities(event: any) {
if (event.value) {
this.cities = this.countries.find(element => { return element.iso2 === event.value }).states;
}
}
<!-- الدولة -->
<div fxFlex="50" fxLayout="column" fxLayoutAlign="space-between center">
<!-- الجنسية: من هنا يمكنك استدعاء أعلام البلدان https://flagcdn.com/ua.svg -->
<mat-form-field class="w-95" appearance="outline">
<mat-label>{{'LABELS.COUNTRY' | translate}}</mat-label>
<mat-select [(ngModel)]="data.country" (selectionChange)="_getCities($event)"
(keydown)="_getCities($event)" [placeholder]="'PLACEHOLDERS.COUNTRY' | translate"
formControlName="country">
<mat-option *ngFor="let item of countries" (click)="getCities(item)"
(change)="getCities(item)" [value]="item.iso2">
<img alt="{{item.iso2}}" class="example-option-img"
[src]="'https://flagcdn.com/' + item.iso2.toLowerCase() + '.svg'"
height="25" width="30">
<span class="mx-2">{{'COUNTRIES.'+ item.iso2 | translate}}</span>
</mat-option>
</mat-select>
<mat-icon *ngIf="data.country" matSuffix class="icon-edit">
<img alt="{{data.country}}" class="example-option-img"
[src]="'https://flagcdn.com/' + data.country.toLowerCase() + '.svg'" height="25"
width="30">
</mat-icon>
<mat-error *ngIf="secondForm.controls.country.errors?.required">
{{'ERRORS.REQUIRED' | translate}}
</mat-error>
</mat-form-field>
</div>
تعليقات
إرسال تعليق