I am passing some data to a modal window in my Ionic/Angular app, but I can not get the select option to be pre-selected based on the data.
My data that is passed in is structured like this:
this.data = {
albums: ["39902"],
user_id: "49"
}
This is some mock data that comes from my API:
{
"albums": [{
"album": [{
"albumID": "27508",
"userID": "49",
"albumName": "Marvel Comics",
"count": "123"
}]
}, {
"album": [{
"albumID": "27509",
"userID": "49",
"albumName": "Baseball",
"count": "77"
}]
}, {
"album": [{
"albumID": "33670",
"userID": "49",
"albumName": "Basketball",
"count": "4"
}]
}, {
"album": [{
"albumID": "39902",
"userID": "49",
"albumName": "Football",
"count": "331"
}]
}, {
"album": [{
"albumID": "39968",
"userID": "49",
"albumName": "Hockey",
"count": "1,552"
}]
}, {
"album": [{
"albumID": "40585",
"userID": "49",
"albumName": "Test Album Name",
"count": "0"
}]
}]
}
In my modal, I call my API service to get the data like this:
this.api.getAlbums().subscribe(response => {
this.albums = response['albums'];
});
In my template, I try and display the selected values like this:
<ion-item lines="full">
<ion-label class="ion-text-wrap">Album</ion-label>
<ion-select multiple="true" [(ngModel)]="data.albums">
<ion-select-option *ngFor="let item of albums" [value]="item.album[0].albumID">{{item.album[0].albumName}}</ion-select-option>
</ion-select>
</ion-item>
When the page loads, the value for the drop down is not selected, however, if I click on the drop down, then the correct value is selected.
Is there a way to get the selected value from this.data
to appear selected in the dropdown?
Bonus points for anyone who can also help remove those silly ellipses from the drop down’s in Ionic.