I am encountering an issue where the nested loop in Angular TypeScript is failing to return

I am facing an issue with my nested loop inside a function. The problem is that it is only returning the default value of false, instead of the value calculated within the loop. Can someone please point out what I might be doing incorrectly?

Provided below is my code snippet for reference. Appreciate your help.

     private checkDeliveryNotesQuantity(line: SaleLine): Observable<boolean> {
        return this.posSalesTableFacade.getStoreSaleBlockList$().pipe(
          map((saleBlockList: SaleBlock[]) => {
            saleBlockList.map(saleBlock => {
              saleBlock.saleLineList.map(saleLineList => {
                console.log('saleLineList', saleLineList);
                return (
                  saleLineList.deliveryNotes &&
                  saleLineList.deliveryNotes.findIndex(
                    item => item.articleId === line.code && item.quantity >= line.missingQuantity
                  ) >= 0
                );
              });
            });
            return false;
          })
        );
      }

Answer №1

Issue with Nested Map:

 private verifyDeliveryQuantity(line: SaleLine): Observable<boolean> {
        return this.posSalesTableFacade.getStoreSaleBlockList$().pipe(
          map((saleBlockList: SaleBlock[]) => {
            return saleBlockList.map(saleBlock => {
              return saleBlock.saleLineList.map(saleLineList => {
                console.log('saleLineList', saleLineList);
                return (
                  saleLineList.deliveryNotes &&
                  saleLineList.deliveryNotes.findIndex(
                    item => item.articleId === line.code && item.quantity >= line.missingQuantity
                  ) >= 0
                );
              });
            });
          })
        );
      }

Please note that the resulting data will be in Array format.

To resolve this issue, you should consider switching from using map to some method

private verifyDeliveryQuantity(line: SaleLine): Observable<boolean> {
        return this.posSalesTableFacade.getStoreSaleBlockList$().pipe(
          map((saleBlockList: SaleBlock[]) => {
            return saleBlockList.some(saleBlock => {
              return saleBlock.saleLineList.some(saleLineList => {
                console.log('saleLineList', saleLineList);
                return (
                  saleLineList.deliveryNotes &&
                  saleLineList.deliveryNotes.findIndex(
                    item => item.articleId === line.code && item.quantity >= line.missingQuantity
                  ) >= 0
                );
              });
            });
          })
        );
      }

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

Struggling with the incorporation of Typescript Augmentation into my customized MUI theme

I'm struggling with my custom theme that has additional key/values causing TS errors when I try to use the design tokens in my app. I know I need to use module augmentation to resolve this issue, but I'm confused about where to implement it and h ...

Proper method for verifying line-clamp in a Vue component

I came across a question that aligns perfectly with my current task - determining if text is truncated or not. The query can be found here: How can I check whether line-clamp is enabled?. It seems like my approach may not be accurate, so any guidance on ho ...

Dealing with substantial ajax responses using JavaScript

Currently, I am in the process of developing a website that utilizes jQuery File Tree. However, there is an issue with the enormous size of the AJAX response from the server - 900 KB and containing approximately 70,000 'files' (which are not actu ...

Transforming control of execution seamlessly between two interactive functions in nodejs

Two functions are used to take input from the CLI using process.stdin. The issue arises when one function is done taking input, as a similar function is called. However, while the control shifts to the second function, the first function continues executin ...

The mysterious case of the missing currentUserObj in Angular with rxjs Subject

I've encountered an issue while trying to pass data from my login component to the user-profile component using an rxjs subject. Despite calling the sendUser method in the login component and subscribing to the observable in the user-profile component ...

Ways to utilize/extract data from an enumeration

Hello there! I am currently diving into the world of React and Typescript, eager to expand my knowledge. Please bear with me if my explanations are not up to par. In my react app, I have a scenario where I created an enum that I want to utilize in two diff ...

The appearance of the Angular app undergoes a change following deployment using ng build

I have been working with Angular for several years now, but only recently delved into using Angular Material components in my latest project. I was pleased with how my layout turned out and ready to push it to production. However, after deployment, the com ...

What is the process for duplicating a set of elements within an svg file and displaying the duplicate at a specific location?

SVG <svg width="200" height="200"> <g id="group"> <rect x="10" y="10" width="50" height="20" fill="teal"></rect> <circle cx=" ...

The 'ref' attribute is not found within the 'IntrinsicAttributes' type

I'm currently working on a TypeScript project using React. Although the code is functional, I keep encountering compiler errors with my ref. Here's an example of the code: Firstly, there's a higher-order component that handles errors: expor ...

Executing JQuery and Ajax calls within a loop

Can I dynamically change the variable in ("xxxxx").html(data) inside a for loop? I've been struggling to figure this out. My goal is to populate an HTML table with JSONP data from multiple ajax calls within a loop, where the URL changes each time. Wh ...

Drop-down selection triggering horizontal auto-scroll

Within my div element, I have a table with dropdowns. The div is set up to be horizontally scrollable. To create the dropdown functionality, I utilized Harvesthq Chosen. Let me provide some context. In Image 1, you'll notice that I've scrolled ...

Having trouble with your JavaScript regex not functioning properly?

I am currently working with an array of arrays and I need to iterate through it to retrieve each word, excluding any "@", punctuation, and hashtags. However, my regular expression seems to be removing certain words entirely from the array and I can't ...

Error: Virtual script not located; possibly absent <script lang="ts" / "allowJs": true / within the jsconfig.json.volar

https://i.sstatic.net/dFaVQ.png I noticed an error in my footer component in VueJs (TypeScript template) as depicted by the image showing blue squiggly lines. ...

Substitute placeholders in array with information using a loop

I have a question regarding implementing an autosort feature in JavaScript. I want my page to automatically sort data rows based on different time intervals selected by the user through checkboxes. The data updates every 3 seconds, and the autosort functio ...

VueJS - Validating Props with Objects

What is the best way to validate Object type props in VueJS to guarantee that certain fields are defined within the object? For instance, I need to make sure that the user prop includes 'name', 'birthDate', and other specific fields. ...

Initiate a POST ajax request to retrieve the file.Let's

I'm currently working on an Asp.Net MVC project and I have a piece of code in my View that looks like this: $.ajax({ beforeSend: function () { LoadStart(); }, complete: function () { LoadStop(); ...

Extending a universal design concept to a new theme within the MUI (Material UI) framework

I have implemented MUI's ThemeProvider and set up a Themes.js file. Within this file, I have defined the globalTheme for managing global styles such as typography and border-radius. My intention is to extend the properties of globalTheme to both light ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...

Concealing or revealing an image with jQuery when hovering

I currently have 3 <a> tags within my html, each containing 2 images. Specifically, the greyscale images are the ones that are visible while the colored ones are set to display:none. I am aiming to achieve a functionality where upon hovering over th ...

ExpressJS and cookies - Struggling to initialize a cookie with express-cookie

I recently followed a tutorial on YouTube (https://youtu.be/hNinO6-bDVM?t=2m33s) that demonstrated how to display a cookie in the developer tools Application tab by adding the following code snippet to the app.js file: var session = require('express- ...