rxjs using combineLatest to filter data stream – stream data is empty when it should not be

Advertisements I am using combine latest in an angular component to bring together a stream of data with a filter text input: export class RecordSearchComponent implements OnDestroy { @Input() gridData: Observable<TrainingRecord[]> = of([]); private filterSubject = new BehaviorSubject<string>(”); private readonly debounceTimeMs = 300; private filterInput$ = this.filterSubject.pipe( debounceTime(this.debounceTimeMs), distinctUntilChanged(), ) filteredData$ = combineLatest([this.filterInput$, this.gridData]).pipe( tap(([filter,… Read More rxjs using combineLatest to filter data stream – stream data is empty when it should not be

Observing @Output Event Emitters in Child Components?

Advertisements How should be go about using / observing parent @Output() event emitters in child components? For example in this demo the child component uses the @Output onGreetingChange like this: <app-greeting [greeting]="onGreetingChange | async"></app-greeting> And this will work if onGreetingChange emits in the AfterViewInit life cycle hook. ngAfterViewInit() { this.onGreetingChange.emit(‘Hola’); } However that produces the… Read More Observing @Output Event Emitters in Child Components?

Subscription after switchMap does not work

Advertisements I have created a Confirmation dialog that returns true or false, based on the user’s choice. This is the function that opens the dialog and handles the responses: public action(id: number): void { this.dialogService.openDialog(ConfirmationComponent).afterClosed() .pipe( switchMap( (result: boolean) => { if (result) { return this.service.doSomething(id); } else { return of(‘cancelled’); } } ) ).subscribe({… Read More Subscription after switchMap does not work

How to return a promise in a nestjs interceptor?

Advertisements I have created a Class implementing NestInterceptor(). As it returns an Observable(), when I have a promise in it, it does not wait the promise to return the data. How should I do that? Here is my code: export class PointsInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler): Observable<any> { var monaddress = context.switchToHttp().getRequest().body… Read More How to return a promise in a nestjs interceptor?

How to do things after an observable gets its data in Angular

Advertisements I am using an observable to retrieve data from an http like: handleError(error:any) { … } getData() { return this._api_service.http.get<JSON>(this._url).pipe(retry(1), catchError(this.handleError)); } loadData() { this.getData().subscribe((data: {}) => { do_something_to_data(data); }); // here I want to do somethings after all the data are loaded do_other_work(); // what should I do here? } It seems do_other_work… Read More How to do things after an observable gets its data in Angular

Setting a variable in the component from an observable

Advertisements I am trying to bind a variable in a component to the content from an observable in a subscribe() function with an anonymous function: ngOnInit() { this.strSub = this._store.select(selectStr).subscribe((data) => console.log(data)); //this.strSub = this._store.select(selectStr).subscribe((data) => {this.str = data}); } The uncommented line runs fine while the commented line throws an error on compilation Type… Read More Setting a variable in the component from an observable

Getting data from observables sync. Angular

Advertisements I am trying to get data from observable. In the subscribe() method I can access this data. But to transfer the response to a global variable does not work. How can I do this? Service: getProducts():Observable<IProduct[]>{ return <Observable<IProduct[]>> this.db.collection(‘products’).valueChanges(); } component: products!: IProduct[]; constructor(private dataService: DataService){} ngOnInit(): void { this.dataService.getProducts().subscribe(response => { console.log(response); //… Read More Getting data from observables sync. Angular

Trigger error or complete from a subscribe

Advertisements I’m new to Angular and I’m trying to trigger the error callback in a subscribe. I’m manipulating a table object and want to throw a toast when an trigger becomes true. Either via an error or complete. // editCollection.component.ts handleMoveRowsDown() { this.collectionsStore.moveRowsDown(this.selectedRows).subscribe( (collection) => { this.table.sorts = []; this.rowsSorted = true; this.collection = collection;… Read More Trigger error or complete from a subscribe

is it possible to use push() to add element into observable array

Advertisements I created an Observable array of type string. like below products: Observable<string[]>; I want to push some elements into products array. I don’t want to use subscribe methods here. it is not allowing me to use the normal push method. see below code this.products.push("mova"); what is the alternative for the above code(push element to… Read More is it possible to use push() to add element into observable array

Difficulty returning the result of an inner function in Angular / Typescript

Advertisements I am really new to Angular and Typescript. I have this function right now createTranscriptionJob(fileToUpload: File, language: string): Observable<void> { this.getSasUrl(fileToUpload.name, language, ldapUserName) .subscribe(response => { const test = this.upload(response.sasUrl, fileToUpload); console.log(test); }); return of(); } First problem currently is that the createTranscriptionJob function is returning basically nothing. Second problem is that the createTranscriptionJob… Read More Difficulty returning the result of an inner function in Angular / Typescript