-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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.
json-alzate, IvanNavarroCode and msmaromi
Metadata
Metadata
Assignees
Labels
No labels