Growing the number of items in the shopping cart

I am facing challenges in adjusting the quantities of products in my cart after adding them. Let me explain the process step by step.

1- I list out the products.

2- I create a function to abbreviate the quantities (miktarKisalt)

3- If the products can be weighed, I simplify the fractions.

4- Next, I develop functions for increasing and decreasing quantities (miktarArttir, miktarAzalt)

5- After updating the item quantities, the cart list is refreshed to display the changes

What I aim for:

To be able to update the quantity of products instantly by clicking the plus and minus buttons without having to refresh the cart list

How can I achieve this?

https://i.sstatic.net/ReDvQ.png

            <div class="count-input space-bottom">
                            <a class="incr-btn" (tap)="miktarAzalt(list.ID, list.MIKTAR, list.FIYAT, list.TUTAR, list.TARTILI) ">–</a>
                            <input class="quantity" readonly type="text" [(ngModel)]="MIKTARMODEL[i]" [value]="miktarAtamaFunc((list.TARTILI == 'E' ? miktarKisalt(list.MIKTAR) : list.MIKTAR),i)" name="quantity" />
                            <a class="incr-btn"  (tap)="miktarArttir(list.ID, list.MIKTAR, list.FIYAT, list.TUTAR, list.TARTILI, i)">+</a>
       </div>

MiktarKisalt Function

MIKTARMODEL : Array<number> = [];

   
miktarAtamaFunc(MIKTAR, INDEX){
 this.MIKTARMODEL[INDEX]= MIKTAR;

}
miktarKisalt(MIKTAR){
        var miktar = Number(MIKTAR);
        return miktar.toFixed(1);
      }

miktarArttir Function

 miktarArttir(ID, MIKTAR, FIYAT, TUTAR, TARTILI){

      let header = new Headers();
      header.append("Content-Type","application/json");
      header.append("Accept","application/json");
      
      var arttirici=1;
      if(TARTILI == "E"){
        MIKTAR = parseFloat(MIKTAR);
        arttirici = 0.1;
      }

      MIKTAR += arttirici;
     this.MIKTARMODEL[INDEX] += arttirici;
     
     var siparisDetayUpdate = "http://sitename.com/function";
     var siparisDetayVeri = JSON.stringify({
       DETAYID : ID,
       MIKTAR : MIKTAR,
       ACIKLAMA : 0
     });

     this.http.post(siparisDetayUpdate,siparisDetayVeri,header).map(res=>res.json()).subscribe(data=>{
       
         this.sepetListesi(); // RELOAD CART LIST

     }, (error)=>{
       this.miktarArttir(ID, MIKTAR, FIYAT, TUTAR, TARTILI);
     });
    
    }

Answer №2

To accomplish this task, you need to nest a Div tag with *ngIf="flag", create a flag variable, and whenever the increase or decrease button is clicked, invoke a function to set the boolean variable to TRUE. As a result, the value will be updated accordingly.

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 could be causing the issue of my application not being able to operate on the specified port on Heroku?

After spending two whole days trying to decipher the Heroku error message with no success, I'm still unable to pinpoint what is causing the issue. 2021-07-18T04:27:08.741998+00:00 app[web.1]: {"level":30,"time":1626582428741,&quo ...

Angular Components: Achieving Full Height Issue with TabsResolved

I'm facing a challenge in making my tab fill the full height of the content underneath it. I've tried different solutions like setting height: 100%, but nothing seems to be working. Here is the HTML code: <mat-tab-group [selectedIndex]=" ...

Introducing ngrx data - the ultimate collection service and data service that offers a custom endpoint

For my entity in ngrx/data, I required a custom PUT request and wanted to ensure its accuracy. Let's say I have a movie library where I can add tags to movies using a PUT request. This is my data service: export class MovieDataService extends Default ...

Retrieve the raw text from the input field instead of the date object

Below is the HTML code for an input field: <div class="input-group input-group-md"> <input id="date" name="date" [readOnly]="disabled" type="text" placeholder="M0/d0/0000 Hh:m0:s0" [placeholder]="pl ...

I am completely baffled by the meaning of this Typescript error

In my code, there is a button component setup like this: export interface ButtonProps { kind?: 'normal' | 'flat' | 'primary'; negative?: boolean; size?: 'small' | 'big'; spinner?: boolean; ...

Tips for invoking an Android function from an AngularJS directive?

I am facing an issue with my HTML that uses an AngularJS directive. This HTML file is being used in an Android WebView, and I want to be able to call an Android method from this directive (Learn how to call Android method from JS here). Below is the code ...

Is having only one FCM token sufficient for storing data from multiple devices?

I'm currently working on an Angular website and looking to send push notifications to users subscribed on both desktop and mobile. I am utilizing Firebase Cloud Messaging for this purpose and wondering if storing a single FCM token will suffice for se ...

The module 'pouchdb' appears to be missing, functioning correctly on Mac but encountering issues on Windows

I have taken over a project built with Ionic that was originally developed on a Mac by my colleague. I am now trying to run the project on my clean Windows 10 PC with Ionic, Cordova, and Python installed. However, I am encountering an error that my colleag ...

Creating a JAR file for an Angular 2 application with Maven

My Front-End application is constructed using Angular2 + Webpack, organized as follows: > app > config > dist > dll > node_modules > src pom.xml package.json ... (other files) Currently, I am exploring th ...

Changes are not being detected in new Angular 2 files

Currently, I am enhancing an Angular 2 project by incorporating new modules. However, the changes I made in these files are not being recognized within the project. I have attempted to research how change detection functions in Angular 2, but have not bee ...

Having trouble getting a local npm installation to work from a specific file path?

After following the instructions from this helpful link to install an npm package through a file path, I encountered an error when attempting to use it: Cannot find module '<module_name>' or its corresponding type declaration Are there an ...

Exploring the similarities between using jQuery AJAX post and Angular

In my current project, I have a legacy application that relies on jQuery and unfortunately cannot incorporate Angular at this time. For one specific task, I need to make an AJAX POST request to consume a web service using jQuery. Interestingly, the same ...

Create Functions to Encapsulate Type Guards

Is it possible to contain a type guard within a function as shown below? function assertArray(value: any): void { if (!Array.isArray(value)) { throw "Not an array" } } // This doesn't work function example1(value: string | []) { a ...

Unable to grab hold of specific child element within parent DOM element

Important Note: Due to the complexity of the issue, the code has been abstracted for better readability Consider a parent component structure like this: <child-component></child-component> <button (click)="doSomeClick()"> Do Some Click ...

Having trouble with Angular 2 not refreshing the view after a database record update

I am working on a CRUD application using Angular 2. The homepage shows a list of cards that users can create, edit, or delete. When I edit a card and click submit on the edit page, it triggers the following function: card-edit.component.ts onSubmit() { ...

Developing typeScript code that can be easily translated and optimized for various web browsers

Can TypeScript alleviate the worry of having to use code such as this (especially when considering browsers like IE that may not support indexOf)? arrValues.indexOf('Sam') > -1 Does the transpiling process in TypeScript generate JavaScript c ...

Specializing Generic Types in Typescript

I'm interested in exploring specialization within Typescript generics, allowing for implementations to vary based on specific type criteria. Here's a simple illustration: const someFunction = <A>() => { return 0; } // something simila ...

What is the best way to showcase custom formatted nested keys within swimlane ngx-datatable?

<ngx-datatable [rows]="services" [columns]="columns"> </ngx-datatable> One way to display nested data is by using the following code snippet: { prop: order.product.price } If you want to display a custom calculation in a row, such as a ...

Issue - The path to the 'fs' module cannot be resolved in ./node_modules/busboy/lib/main.js

After adding a new React component to my NextJS app, I encountered a mysterious error in my local development environment: wait - compiling... error - ./node_modules/busboy/lib/main.js:1:0 Module not found: Can't resolve 'fs' null Interest ...

Defined a data type using Typescript, however, the underlying Javascript code is operating with an incorrect data type

Recently delving into Typescript and following along with an educational video. Encountered a strange behavior that seems like a bug. For instance: const json = '{"x": 10, "y":10}'; const coordinates: { x: number; y: number } = JSON.parse(json); ...