I’m trying to conditionally render a paragraph with information stored in a component property but ngIf directive is not even showing the else template, cannot even test if the changes detection is working for the way I set the property.
src/pages/booking/booking.html
:
<!-- ion-header -->
<ion-content padding>
<form [formGroup]="formGroup">
<ion-list>
<!-- ... ion-items --->
<a ion-item id="booking_select_city" (click)="selectCity ()">
<ion-label>Municipio</ion-label>
<p *ngIf="selectedCity; else noSelectedCity">{{ selectedCity.name }}</p>
<ng-template #noSelectedCity><p>Seleccione...</p></ng-template>
</a>
<ion-item>
<!-- ... more ion-items --->
</ion-list>
</form>
</ion-content>
src/pages/booking/booking.ts
/* imports */
@IonicPage({
name: 'booking'
})
@Component({
selector: 'page-booking',
templateUrl: 'booking.html'
})
export class BookingPage implements OnInit {
/* properties */
public selectedCity : AdministrativeZone;
/* constructor and other methods */
public selectCity () : void {
const modal = this._modalCtrl.create ('city-select');
modal.onDidDismiss ((data : AdministrativeZone) => {
this.selectedCity = data;
});
modal.present ();
}
}
The text seleccione...
is not being rendered on ionic-app-scripts serve
nor even on spec-tests with TestBed. And when I choose the city from the modal, the view doesn’t change either.
What am I doing wrong?