Subscription after switchMap does not work

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({ next:… Read More Subscription after switchMap does not work

How to return a promise in a nestjs interceptor?

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 var… Read More How to return a promise in a nestjs interceptor?

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

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 will… Read More How to do things after an observable gets its data in Angular

Setting a variable in the component from an observable

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 ‘void’… Read More Setting a variable in the component from an observable

Getting data from observables sync. Angular

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); // return… Read More Getting data from observables sync. Angular

Trigger error or complete from a subscribe

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; this.table.rows… Read More Trigger error or complete from a subscribe

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

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 an… 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

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 function… Read More Difficulty returning the result of an inner function in Angular / Typescript

Angular: wait for Observable inside a function before returning result

I need help with the following function: getUser(uuid: string): Observable<WowUserDataModel> { let user: WowUserDataModel = { login: null, userUuid: uuid, firstName: null, lastName: null, displayName: null, email: null, authorities: null }; return this.http.get(WowUrlProvider.gateway.wowUserAuthorities.replace(‘{userUuid}’, uuid.toUpperCase())).pipe( map((authorities) => user.authorities = authorities, ) ); } What I need: to wait for the this.http.api call (which returns Observable) to… Read More Angular: wait for Observable inside a function before returning result