I included the following code in my HTML file:
<ion-col col-3 align="right">
<ion-item>
<ion-label>Show as</ion-label>
<ion-select [ngModel]="SelectedView" (ngModelChange)="onViewChange($event)>
<ion-option value="List">List</ion-option>
<ion-option value="Map">Map</ion-option>
</ion-select>
</ion-item>
</ion-col>
And in my customer.ts file, I have the following code:
export class customerpage implements OnInit {
constructor(public modalCtrl: ModalController,
public popoverCtrl: PopoverController,
private _customerservice: CustomersService,
public navCtrl: NavController,
public navParams: NavParams) {
this.ListPositions = [];
this.customersArray = [];
this.customersView = [];
}
ngOnInit() {
this.SelectedCategory = "";
this.customersArray = [];
this.customersView = [];
setTimeout(() => {
this.GetCustomers();
}, 500);
}
GetCustomers() {
const arrayofroles$ = this._customerservice.GetAllCustomers();
arrayofroles$.subscribe(res => {
this.customersArray = res;
this.customersView = this.customersArray;
},
err => { },
() => {
this.loadingCustomers = false;
});
}
ionViewDidLoad(): void {
}
onViewChange(event: any, Customers: any) {
this.initMap(Customers);
}
initMap(Customers: any) {
this.customersView; // UNDEFINED!
}
}
Initially, during ngInit, I load the customersview from the database. When onViewChange is triggered from the HTML, I call the initMap function and try to access customersView, but it returns undefined for my local variable.