Waiting for a response in Typescript before running a function

Is there a way to execute a function after the response is completed without using setTimeout()? I am facing an issue with uploading large files where the waiting time is insufficient.

 this.orderTestService.orderObservable$

.pipe(untilDestroyed(this))

.subscribe((response) => {    

  if(response){

    setTimeout( () => {

      this.service.getDocuments(); }, 1000 );

  }

 }

});

Answer №1

One option is to utilize the finalize operator, which will trigger your function upon completion of the observable.

this.orderTestService.orderObservable$
  .pipe(
    untilDestroyed(this),
    finalize(() => {
      this.service.getDocuments();
    })
  )
  .subscribe((response) => {
    if (response) {
      // Process successful response 
    }
  });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am working in Angular 13 and attempting to dynamically assign attributes to an SVG HTML element by passing in values from variables declared in a TypeScript file

Within a specific HTML file of my Angular13 app, I'm aiming to dynamically bind a list of attributes and their values to an element using Angular's double-binding approach {{attribute value}}. This will allow me to display a series of social medi ...

Issue with Authentication - Sequencing of Observables and Promises in Angular/REST APIs

I'm currently utilizing Angular 7 and have recently started working on a new Angular application project at my agency. One of my colleagues has already set up the backend (Restful), so I began by focusing on implementing the Authentication Feature. T ...

What is the best way to utilize moment.js for adding days while excluding weekends?

I have a requirement to set a default follow-up date that is two days ahead of the current date. The existing code for this functionality is as follows: const Notify = moment().add(2, 'days').toDate(); Now, I need to modify this code to exclude ...

Limit file upload size to less than 1MB in Angular 2 with typescript using ng2-file-upload

Having issue with my code - I can't upload a file larger than 1mb even though maxFileSize is set to 50mb. Can anyone help me troubleshoot? @Component({ moduleId: module.id, selector: 'NeedAnalysisConsult', templateUrl: 'nee ...

In React-Native, implement a function that updates one state based on changes in another state

I need to trigger a function when a specific state changes. However, I encountered the error 'maximum update depth reached'. This seems illogical as the function should only respond to changes from stateA to update stateB. I attempted using setSt ...

React component not displaying any content due to ternary operator condition being met with variable equal to 0

Seeking to display a React component upon clicking another component. When clicked, I assign the eventKey of the component to a savedId in order to render the corresponding data from the array at that index. Click Action <ListGroup> {data.map((it ...

Is it possible to confirm the authenticity of a hashed secret without having knowledge of the salt used

My method of storing API-Keys involves hashing and saving them in a database. ... async function createToken(userId:number) { ... const salt=await bcrypt.genSalt(15) const hash=await bcrypt.hash(token, salt) await db.store({userId,hash}) } ...

Tips for creating an Angular testing scenario that encompasses the use of array.find()

I need assistance in writing a test case for the following method. I have created the code snippet below but it is not helping to improve/change the code coverage. Can anyone please guide me on what I might be doing incorrectly? Component remove(item: str ...

Issue encountered during rendering: "TypeError: Attempting to access property '_t' of an undefined object" while running a Unit Test using Jest

I spent hours troubleshooting a unit test for my Vue.js component, but no matter how much I searched the internet, I kept encountering this error: console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884 TypeError: Cannot read property ' ...

Running your Angular application on a Node server: Step-by-step guide

I am looking to deploy my application using express on a Node server. This is the content of my server.js file: var express = require('express'); var path = require('path'); var app = express(); app.get('/', (req, res) => ...

Modifying PDF files using Angular 4

Encountering a CORS problem in node v8.9.4. Error message - Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200& ...

converting HTML values to TypeScript

I'm a beginner with Angular and could use some assistance. Currently, I have two components - one for the index and another for navigation. Within the index component, there are subcomponents that change based on the value of a variable called produ ...

Sending multiple text fields along with a file to an API using Angular

I'm currently facing a challenge with uploading a file to an API endpoint that I created using Laravel, using an HTML form. The upload works fine when only the file is involved. However, I also need to include some basic text fields in the request. T ...

How can one effectively import and save data from a CSV file into an array comprised of objects?

I am looking to read a CSV file and store it in a variable for future access, preferably as an array of objects. However, when trying the following code snippet: const csv = fs .createReadStream('data.csv') .pipe(csv.default({ separator: &ap ...

Implementing theme in Monaco editor without initializing an instance

I recently developed a web application incorporating Monaco Editor. To enhance user experience, I also integrated Monaco for syntax highlighting in static code blocks. Following guidance from this source, I successfully implemented syntax highlighting wit ...

There is no value inputted into the file

I'm facing a small issue while trying to retrieve the value from my input of type="file". Here is the code snippet: <tr ng-repeat="imagenDatos in tableImagenesPunto | filter: busquedaDatosPunto " > <td>PNG</td> <td>{{imag ...

There are occasional instances in Angular 6 when gapi is not defined

I am currently developing an app with Angular 6 that allows users to log in using the Google API. Although everything is working smoothly, I encounter a problem at times when the 'client' library fails to load and displays an error stating gapi i ...

Encoding URLs in Angular 2 for HTTP POST requests

I am attempting to utilize a service through post with Angular2. Below is my code snippet: var m_dataRequest = this.buildLoginUserPasswordRequest(password, key); let headers = new Headers({ 'Accept': '*/*', &apos ...

What could be the reason for encountering a Typescript ts(2345) error while trying to pass a mocked constant to .mockResolvedValue()?

Within my test.tsx file, I have the following code snippet: test('Photos will load', async () => { const mockCuratedPhotos = jest.spyOn(endpoints, 'getCuratedPhotos'); mockCuratedPhotos.mockResolvedValue(mockPhotos); awa ...

Setting up eslint for your new react project---Would you like any further

I am currently working on a TypeScript-based React application. To start off, I used the following command to create my React app with TypeScript template: npx create-react-app test-app --template typescript It's worth noting that eslint comes pre-co ...