Repository navigation
Closed
Description
Bug Report
Ionic Info
Ionic:
ionic (Ionic CLI) : 4.1.2
Ionic Framework : @ionic/angular 4.0.0-beta.7
@angular-devkit/core : 0.7.0-rc.3
@angular-devkit/schematics : 0.7.0-rc.3
@angular/cli : 6.1.5
@ionic/ng-toolkit : 1.0.0
@ionic/schematics-angular : 1.0.1
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.0.2, (and 4 other plugins)
System:
Android SDK Tools : 26.1.1 (D:\dev\androidSDK)
NodeJS : v8.11.3 (D:\dev\nodejs\node.exe)
npm : 6.4.1
OS : Windows 7
Describe the Bug
When empty array is supplied to *ngFor in ion-select-option element then it displays old values
Steps to Reproduce
- Select course two
- Open instructors select (it is empty)
- Select course one
- Open instructors select (it contains two elements as expected)
- Select course two
- Open instructors select - here is the bug - it is not empty, contains values from step 4
Related Code
Simplified but it shows the bug
<ion-item>
<ion-label>Courses</ion-label>
<ion-select (ionChange)="courseChanged($event)" interface="action-sheet">
<ion-select-option *ngFor="let course of courses$ | async" [value]="course.id">
{{course.name}}
</ion-select-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label>Instructors</ion-label>
<ion-select interface="action-sheet">
<ion-select-option *ngFor="let instructor of instructors$ | async" [value]="instructor.id">
{{instructor.name}}
</ion-select-option>
</ion-select>
</ion-item>
<p>Here are displayed array values</p>
<ion-item *ngFor="let instructor of instructors$ | async">
{{instructor.name}}
</ion-item>
courseId$ = new BehaviorSubject<number>(0);
courses$: Observable<any[]>;
instructors$: Observable<any[]>;
ngOnInit() {
this.courses$ = this.getAllCourses();
this.instructors$ = this.courseId$.pipe(
switchMap(id => this.getInstructorsNamesByCourseId(id)),
tap(console.log)
);
}
setCourseId(id: number) {
this.courseId$.next(id);
}
courseChanged(e: CustomEvent) {
this.setCourseId(e.detail.value);
}
// api call
getAllCourses(): Observable<any[]> {
return of([
{id: 1, name: 'Course one (2 instructors)'},
{id: 2, name: 'Course two (empty)'},
]);
}
// api call
getInstructorsNamesByCourseId(id: number): Observable<any[]> {
if (id === 1) {
return of([
{id: 1, name: 'Instructor One'},
{id: 2, name: 'Instructor Two'},
]);
} else {
return of([]);
}
}
Expected Behavior
Instructors select should always be empty when course selected item is (course two empty).
Correct values are always displayed below selects.
Reacted by Json Alzate, Ivan Navarro and Muhammad S Maromi
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
No fields configured for issues without a type.
Activity
RomeoDenis commentedon Sep 16, 2018
This issue still persists in 4.0.0-beta.11
paulstelzer commentedon Dec 4, 2018
I this still an issue in
beta.17?wozniak-michal commentedon Dec 4, 2018
Yes, issue still exists. As a workaround I am disabling
ion-selects controls.Current ionic info:
json-alzate commentedon Aug 16, 2019
Still is a bug; but I find a little solution, maybe no is very clear...but you can destroy the select and rebuild again:
fix(all): component reusage (#18963)
fix(all): component reusage (#18963)
fix(all): component reusage (#18963)
liamdebeasi commentedon Sep 4, 2019
A fix for this is available in Ionic 4.9.0. For any new bugs, please create a new issue.
Thanks!
ionitron-bot commentedon Oct 4, 2019
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.