When a user enters the page, I’m setting blastLocation=defaultLocation
(defaultLocation being passed as a param), and I want defaultLocation.locationName
to be preselected in the ion-select
component. Then, users have the option to select from an array of alternative locations
, which are also being passed in as a param. These locations
are objects, not strings, but they all contain a location.locationName
attribute, which is what the ion-select
component displays through interpolation {{}}. Everything works fine…except that I can’t get the defaultLocation.locationName
to show as pre-selected.
constructor(nav, navParams) {
this.nav = nav;
this.navParams = navParams;
this.blastLocation = this.navParams.get('pool').defaultLocation;
this.locations = this.navParams.get('pool').locations; // locations is an array of location objects. Each location object contains a locationName property, amongst others.
…and here’s the actual HTML to match:
<ion-list>
<ion-item>
<ion-icon item-left name="pin"></ion-icon>
<ion-label></ion-label>
<ion-select [(ngModel)]="blastLocation">
<ion-option *ngFor="#location of locations" [value]="location">{{location.locationName}}</ion-option>
</ion-select>
</ion-item>
</ion-list>
It makes sense, right? A user’s default location should be preselected when they enter the page to select a location. This would be easy if it was a just an array of strings, but is proving to be very difficult with an array of objects containing various string attributes. I came up with a messy hack that allows me to display defaultLocation.locationName
in the label
component, since I can set that manually with <ion-label>{{blastLocation.locationName}}<ion-label>
. That way, when the user enters the page, blastLocation.locationName=defaultLocation.locationName
, and when the user selects from the list of locations, then blastLocation.locationName=location.locationName
. The obvious messiness here is that I then have to hide the area where selected items are normally displayed.
On a completely separate note, how can I set an entire checkbox list = to true by default? For example, upon entering a page, I want every checkbox of the following code to be checked by default.
<ion-list>
<ion-item *ngFor="#item of items">
<ion-checkbox></ion-checkbox>
<ion-label>
{{item}}
</ion-label>
</ion-item>
</ion-list>
Simply setting checked="true"
inside <ion-checkbox></ion-checkbox>
does not work.
I know this was a lot, thanks in advance if you have any suggestions
Matt