Skip to content

Commit

Permalink
Merge pull request #448 from almothafar/master
Browse files Browse the repository at this point in the history
RxJS 7 migration
  • Loading branch information
almothafar authored Sep 16, 2024
2 parents bbf048f + 04c81ad commit 46499d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [18.0.0] Major Update

- Upgraded to support Angular 18
- Migration for deprecated Observable<T> params
- Adding e2e smock test for the project removing deprecated protractor adding cypress

## [17.0.0] Major Update
Expand Down
43 changes: 22 additions & 21 deletions projects/auto-complete/src/lib/auto-complete.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import { NguiAutoCompleteService } from './auto-complete.service';
import { Observable } from 'rxjs';

@Component({
selector: 'ngui-auto-complete',
Expand Down Expand Up @@ -132,39 +133,39 @@ export class NguiAutoCompleteComponent implements OnInit {
this.filteredList = this.filteredList.slice(0, this.maxNumList);
}

} else { // remote source
} else {// remote source
this.isLoading = true;

if (typeof this.source === 'function') {
// custom function that returns observable
this.source(keyword).subscribe(
(resp) => {

if (this.pathToData) {
const paths = this.pathToData.split('.');
paths.forEach((prop) => resp = resp[prop]);
}

this.filteredList = resp;
if (this.maxNumList) {
this.filteredList = this.filteredList.slice(0, this.maxNumList);
}
},
(error) => console.warn(error),
() => this.isLoading = false // complete
(this.source(keyword) as Observable<any>).subscribe({
next: (resp) => {
if (this.pathToData) {
const paths = this.pathToData.split('.');
paths.forEach((prop) => resp = resp[prop]);
}

this.filteredList = resp;
if (this.maxNumList) {
this.filteredList = this.filteredList.slice(0, this.maxNumList);
}
},
error: (error) => console.warn(error),
complete: () => this.isLoading = false
}
);
} else {
// remote source

this.autoComplete.getRemoteData(keyword).subscribe((resp) => {
this.autoComplete.getRemoteData(keyword).subscribe({
next: (resp) => {
this.filteredList = resp ? resp : [];
if (this.maxNumList) {
this.filteredList = this.filteredList.slice(0, this.maxNumList);
}
},
(error) => console.warn(error),
() => this.isLoading = false // complete
);
error: (error) => console.warn(error),
complete: () => this.isLoading = false
});
}
}
}
Expand Down

0 comments on commit 46499d5

Please sign in to comment.