Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Passing a function in ng-bootstrap modal

My cart-component code is

<ng-template #mymodal let-modal>

        <div class="modal-wrap">
            <div class="modal-header">
                <h5 class="modal-title" id="modal-basic-title">Removing Item from Cart...</h5>
            </div>
            <div class="modal-body">
                Are you sure? Proceeding will remove item from cart.
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" (click)="removeItem(item)">Yes</button>
                <button type="button" class="btn btn-danger" (click)="modal.close('Save click')">No</button>
            </div>
        </div>
    </ng-template>

Modal Code in component.ts

open(content: any) {
    this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }
  
  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return  `with: ${reason}`;
    }
  }

Cart Code in component - this uses the cart service

removeItem(item: any){
    this.cartService.removeCartItem(item);
  }

Cart Service Code

removeCartItem(product: any){
    this.cartItemList.map((a:any, index:any)=>{
      if(product.id=== a.id){
        this.cartItemList.splice(index,1);
      }
    })
    this.productList.next(this.cartItemList);
  }

How do I make this work? Intial error - Propery 'item' does not exist on type 'AddtoCartbutton', I tried declaring item in cart component but when I press delete button I get undefined.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!