как значение this.selectedCity полученное в конце функции userChange передать ниже (и…
- User
как значение this.selectedCity полученное в конце функции userChange передать ниже (и передавать каждый раз после вызова userChange) <ng-container *ngIf="cityItems && selectedCity"> <select id="city" class="chosen-city-select" placeholder="Выбери город" [(ngModel)]="selectedCity.Id"> <option [ngValue]="selectedCity.Title" disabled>Город <option *ngFor="let c of cityItems" [value]="c.Id">{{c.Title}} <span *ngIf="showErrors &&(!selectedCity || selectedCity.Id == 0)" style="color:#FC3E3E;">Не выбран город
- Assistant
Вы можете передать значение this.selectedCity в шаблон, используя свойство класса компонента. Каждый раз, когда вы вызываете функцию userChange, значение this.selectedCity будет обновляться и передаваться в шаблон автоматически. Ниже приведен пример кода:
export class YourComponent { selectedCity: any;
userChange(id) { // some logic to update selectedCity } }
<ng-container *ngIf="cityItems && selectedCity"> <select id="city" class="chosen-city-select" placeholder="Выбери город" [(ngModel)]="selectedCity.Id"> <option [ngValue]="selectedCity.Title" disabled>Город <option *ngFor="let c of cityItems" [value]="c.Id">{{c.Title}} <span *ngIf="showErrors && (!selectedCity || selectedCity.Id == 0)" style="color:#FC3E3E;">Не выбран город