Must run the angular code in a sequential order

I need to run the code in a specific order; first the foreach loop should be executed, followed by a call to the getHistory() method. Your assistance is greatly appreciated.

const execute = async()=>{

         await this.currentContent.forEach(async currentContent => {
          if (!currentContent.footnote) {

            let tempContent: any = await this._http.get(`VersionHistory/ContentAuditTrail/${currentContent.id}/${this.newDatetimeSelection}`).toPromise();
            if (tempContent){
              console.info('end time call : raw content');
              currentContent.rawContent = tempContent.value;

            }
            // content.rawContent = await this._http.get(`VersionHistory/ContentAuditTrail/${c.id}/${this.oldDatetimeSelection}`).toPromise();
          } else {

            let newcontent: any = await this._http.get(`VersionHistory/ContentFootnoteAuditTrail/${currentContent.footnote.id}/${this.newDatetimeSelection}`).toPromise();
            if (newcontent) {
              console.info('end time call : footnote content');
              currentContent.footnote.footnote = newcontent.value;

            }
          }
        })
        //setTimeout(() => {
          console.info('end time call');
          this.getHistory();
        //}, 4000);
      }

      execute();

Answer №1

It could look a bit like this -

Running Promise.all() on this.currentContent.map(##first part of your code##))
    .then(() => {
        Printing out 'end time call';
        Now it's time to call this.getHistory();
})

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

What sets apart ".. let i = index" from "..let i as index"?

Having recently delved into the world of Angular, I've been scouring YouTube for tutorials. While watching, I noticed some developers using ""let item of items; let i as index"" while others used ""let item of items; let i = index" ...

What are the steps to downloading a server-generated image with user data from the client using Express?

I am facing a challenge with downloading a server-generated image immediately after it is created. My current approach involves using fetch to send user input data (bypassing HTML forms). Although the image is successfully generated on the server, I am str ...

The issue of onClick failing to function when paired with the addEventListener for the

Looking into a react component for a profile button that opens a menu with three options: My Profile, Settings, and Logout. The issue seems to be with the onClick event on the a tags not working as expected (the console.log is not being printed). Interes ...

importing files from Uploadcare using ngCordova MediaFile

I am facing an issue while attempting to upload a sound file from ngCordova's $cordovaCapture service to UploadCare. The `uploadcare.fileFrom('object')` function is failing with an 'upload' error even though I have set the public k ...

The Jest mock for dates is completely ineffective and always ends up returning the constructor

beforeAll(() => { ... const mockedData = '2020-11-26T00:00:00.000Z' jest.spyOn(global, 'Date').mockImplementation(() => mockedData) Date.now = () => 1606348800 }) describe('getIventory', () => { ...

How to eliminate the unnecessary gap between rows in a Vue div displayed as a grid

I have recently started working with Vue and in my current project, I encountered a challenge where I needed to display 2 players in each row within a div. To achieve this, I utilized the display: grid; CSS property on the playerDiv id. However, I am facin ...

Font rendering issue in Chrome extension

I have been diligently following various tutorials on incorporating a webfont into my Chrome extension, but unfortunately, none of them seem to be working for me. Despite all my efforts, the font remains unchanged and still appears as the default ugly font ...

`Count the number of rows needed to accommodate text line breaks within a div element`

Is there a method to determine the number of lines that text breaks into using the CSS property word-break: break-all? For example, if I have a div like this: <div>Sample text to check how many lines the text is broken into</div> And the corr ...

NextJS for Self-hosting Fonts

I'm facing difficulties with self-hosting webfonts in my NextJS application. The browser is trying to access the fonts using this URL: localhost:3000/_next/static/css/fonts/Avenir.woff2 However, the actual path for these fonts is: _project_dir/static ...

What is the best way to store React form data in a queue for future processing?

I am currently developing a ticketing system in React, utilizing Node.js for the backend and Python for the email server. My goal is to process form submissions by extracting all the form data, creating an instance of a plain JavaScript class with only a ...

Warning: An unexpected issue occurred due to an invalid integer being entered as Not a Number (NaN

I've encountered an issue trying to pass data into the "amount" parameter. From the client, I'm sending the "price" to the server successfully. Upon checking the console output, I see the correct information is being received. The typeof check ...

Consistently directing to a single page on the Node Js web server

I'm in the process of creating a website with multiple HTML pages. Currently, I have code that successfully links to the login page, but unfortunately, the localstores page also directs to the login page. const express = require('express') ...

The functionality of the MVC jQuery grid is currently malfunctioning

Recently, I attempted to integrate a jQuery grid plugin from gijgo.com into my MVC application. Following the instructions provided on c-sharpcorner and/or codeproject meticulously, however, upon running the application, I encountered a troubling JavaScrip ...

What is the best way to explore JavaScript text using Firebug?

The search function (magnifying glass) located at the top-right hand corner of Firebug does not have the capability to search within JavaScript blocks. For instance, if I have the following code snippet: <script type="text/javascript"> var fooBa ...

Page Content Fails to Load Without Reloading

I am currently working on a simple project using React with TypeScript, and I have run into an issue where the page content does not refresh as expected without having to reload the page. I am unsure of the underlying cause of this behavior. I have include ...

Execute a function at a designated time without having to open the application

Currently in the process of developing a .NET Core application with Angular and Ignite UI. I was wondering if there is a way to execute a function in the background without requiring the webpage to be open. For instance, would it be feasible to automatica ...

What is the best way to send an HTML form variable to a Perl script using AJAX?

My goal is to pass the HTML variable from the list menu to the Perl script using POST. However, when I try to do this, the jQuery ajax() function executes the Perl script without including the value obtained from document.getElementById. Below is the sni ...

Separate modules in the Webpack.mix.js file don't produce any output files in the public folder

I've recently been tackling a Laravel project with an extensive webpack.mix.js file residing in the root directory, boasting nearly 5000 lines of code. In an effort to enhance organization and maintainability, I've opted to break it down into ind ...

Is there a way to streamline the process of connecting multiple ajax requests automatically?

After reviewing the lower portion of my function, I realized that I need to repeat info(url_part1 + next + url_part2, function(next) { multiple times. Is there a more efficient way to accomplish this task, perhaps utilizing some type of loop? I have been b ...

Best practices for customizing properties not directly accessible in the primeng scheduler component

During my review of the documentation, I observed that the scheduler component does not offer access to the slotLabelFormat found in the fullcalendar control. Can you provide any recommendations on how to set this property? Appreciatively, Luis ...