I'm very new to mobile app development and ionic so forgive me if this is a silly question.
I want my app to be able to choose from a list of exercises that are giving by an API and I want to be able to pass that data (in this case its just the name of the exercise I want) to another page but when I try to log it returns as undefined. I think it might be an issue with it being an object rather than a string but I'm not sure.
Here is my code:
<ion-header>
<ion-toolbar>
<ion-title>Add Exercise</ion-title>
<ion-buttons slot ="end">
<ion-button (click)="dismissModal()">Close</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list *ngFor="let results of exerciseList">
<ion-item button (click)="addExercise($exercise)" [(ngModel)]="exercise" ngDefaultControl>
{{results.name}}
</ion-item>
</ion-list>
</ion-content>
and here is my typescript code:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ModalController } from '@ionic/angular';
@Component({
selector: 'app-exercise-modal',
templateUrl: './exercise-modal.component.html',
styleUrls: ['./exercise-modal.component.scss'],
})
export class ExerciseModalComponent implements OnInit {
public exerciseList: any = "";
exerciseName : any;
constructor(private http: HttpClient, private modalCtrl: ModalController) { }
ngOnInit() {
console.log("inside create")
this.http.get('https://wger.de/api/v2/exercise/').subscribe((response) => {console.log(response);this.exerciseList = response['results']});
}
dismissModal(){
this.modalCtrl.dismiss();
}
addExercise(exercise: any){
this.exerciseName = this.exerciseList;
console.log(this.exerciseName);
}
}