The modal stubbornly refuses to close

The main component responsible for initiating the process is /new-order.

Upon clicking on the confirm button, a modal window appears.

<div class="col-12">
  <button type="button" class="btn btn-primary m-1" (click)="openConfirmModal()">Confirm</button>
</div>

Here is the function used to open the modal:

openConfirmModal(): void {
    const modalRef = this.modalService.show(NewOrderConfirmModalComponent, {
        ...NOT_CLOSABLE_MODAL_OPTIONS,
        class: 'modal-dialog-centered modal-lg',
        ariaLabelledBy: 'modal-error-title',
        initialState: {
            orderToConfirm: this.order,
        }
    });
    modalRef.content!.closeModal.pipe(
        takeUntil(this.unsubscribe$)
    ).subscribe(() => {
        modalRef?.hide();
    });
}

View Image Here

View Image Here

Now, let's shift focus to the child component -

new-order-confirm-modal.component.html

The corresponding HTML code is as follows:

<button type="button" class="btn-close" aria-label="Close button" aria-describedby="modal-title" click="close()"></button>

Below is the TypeScript file associated with this component:

export class NewOrderConfirmModalComponent implements OnInit {
  @Input() orderToConfirm!:  Order;  
  private unsubscribe$ = new Subject<void>();
  @Output() closeModal = new EventEmitter<void>();

  
  constructor(
    public modal: BsModalRef,
    private router: Router,
    private location: Location,
    private service: NewOrderService
  ) { }
  
  ...
  
  close(): void {
    this.closeModal.emit();
  }

An issue arises when attempting to close the modal by clicking on the "X" button...

EDIT

import { EventEmitter } from '@angular/core';
import * as i0 from "@angular/core";
export declare class BsModalRef<T = any> {
    /**
     * Event triggered when the modal behind the reference begins to hide
     */
    onHide?: EventEmitter<unknown>;
    /**
     * Event triggered upon completion of hiding the modal behind the reference
     */
    onHidden?: EventEmitter<unknown>;
    /**
     * Allows user to provide an ID for the modal, else a unique number is assigned
     */
    id?: number | string;
    /**
     * Reference to a component inside the modal. Null if modal was created with TemplateRef
     */
    content?: T;
    /**
     * Hides the modal
     */
    hide: () => void;
    /**
     * Sets a new class name for the modal window
     */
    setClass: (newClass: string) => void;
    static ɵfac: i0.ɵɵFactoryDeclaration<BsModalRef<any>, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<BsModalRef<any>>;
}

Answer №1

"The modal is not closing when the button is clicked" because the parenthesis for the click event are missing. Simply adding them will resolve the issue.

<button type="button" class="btn-close" aria-label="Close button" aria-describedby="modal-title" (click)="close()"></button>

Answer №2

shut(): void {
    this.popup.hide();
    this.emitClosePopup.emit();
}

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

Selecting ion-tabs causes the margin-top of scroll-content to be destroyed

Check out the Stackblitz Demo I'm encountering a major issue with the Navigation of Tabs. On my main page (without Tabs), there are simple buttons that pass different navparams to pre-select a specific tab. If you take a look at the demo and click t ...

Stop the current HTTP request and initiate a new one asynchronously

My custom component showcases a detailed view of a selected building along with a list of its units (apartments). Below is the HTML code for this component: <div *ngIf="$building | async as building"> ... <div *ngIf="$buildingUnit ...

The variable's Ionic value is not being displayed in the HTML

I recently developed a new Ionic application and encountered an issue while attempting to display a variable value in the HTML. Without making any modifications, this is the current state of my page after creating the app. import { IonicModule } from &ap ...

I'm trying to troubleshoot this issue - the duration is showing up as NaN years, NaN months, NaN weeks, NaN days, NaN

Currently I am troubleshooting an issue in my ionic project. I have a button and I want to display the date that the user selects. This is my code: age.component.ts import { Component, OnInit } from '@angular/core'; import * as moment from &apo ...

When the browser is refreshed in Angular, the default root component will show up instead of the one specified in routes

I'm facing an issue with browser refresh on my Angular application. Every time I reload the page, either by refreshing the browser or entering a URL, the app redirects to the "/" route. Despite trying various solutions, none seemed to resolve the iss ...

TS2345: Cannot assign type '(item: cType) => cType' to type '(value: Object, index: number, array: Object[]) => cType' within the parameter

I am currently working on a project using Angular 13 and Typescript 4.5.2. In addition, I am incorporating the Syncfusion library in my development process, specifically utilizing the datagrid component for managing table data. For reference, you can che ...

Error message: In the combination of NextJs and Redux, an issue has occurred where the program is unable to access properties of null, specifically in

I am just getting started with Next and redux, but I am facing an issue. The error shown above occurs when trying to select a redux value from the store. I have attempted using raw useSelector from redux toolkit, but it still results in the same error. ...

Guide on integrating react-tether with react-dom createPortal for custom styling of tethered components based on their target components

Within a Component, I am rendering buttons each with its own tooltip. The challenge is to make the tooltip appear upon hovering over the button since the tooltip may contain more than just text and cannot be solely created with CSS. The solution involves ...

How can I effortlessly retrieve the Current Route Path Name in Angular?

I needed to find out the current route's path name and discovered this simple solution. this.route.snapshot.firstChild.url[0].path Is there a more efficient method for achieving this? Appreciate any advice! ...

Guide to updating the canvas in Chart.js based on a user-defined x-axis range

What I currently have: My chart.js canvas displays values on the x-axis ranging from 1 to 9. Users can input a new range to view a different scope, with default limits set at start = 3 and end = 6 in my repository. I already have a function that restrict ...

What is the solution to the error message "Unable to assign property of undefined"?

I am currently working on an angular countdown timer and encountering a TypeError when attempting to access a variable from another component. I am struggling to identify the root cause of this issue. Here is the video tutorial that I am using as a referen ...

Can React Hooks API be used in TypeScript without using JSX?

After attempting to convert the JSX version of the React Hooks API demo into one without JSX, following the guidelines provided in react-without-jsx documentation, I ended up with the code below: import React, { useState } from 'react'; import R ...

What could be causing the failure of the subscribe function to interpret the API response

I want to retrieve user information by using their identification number through a method component.ts identificacion:any = this.route.snapshot.paramMap.get('identificacion'); constructor(private route: ActivatedRoute, private dataService: ...

Using the novalidate attribute in Angular 4.0.0

Since migrating to angular 4, I have encountered a peculiar issue with my template-driven form. The required attribute on the input field appears to be malfunctioning. It seems like the form has the novalidate attribute by default, preventing HTML5 validat ...

What is the process of loading data into mdbCharts following an API call?

I am currently having an issue with loading a PieGraph using mdbChart after making an API call. The problem is that I am getting errors while trying to load the data. Here is my code: public chartType: string = 'pie'; public chartDatasets: Array ...

Utilizing a TypeScript function to trigger an action from within a Chart.js option callback

Currently, I am utilizing a wrapper for Chart.js that enables an animation callback to signify when the chart has finished drawing. The chart options in my code are set up like this: public chartOptions: any = { animation: { duration: 2000, ...

What is the process for automatically initiating a service when importing a module in Angular?

I am curious about how I can automatically run a service within a module upon importing it, without the need for manual service injection and execution. This functionality is similar to how the RouterModule operates. @NgModule({ imports: [ Browser ...

Deleting elements from an array of objects in Angular Would you like help with

I have a JSON structure and I need to remove the entire StartGeotag object from the array. [{ CreatedDate: "2022-02-17T10:30:07.0442288Z" DeletedDate: null ProjectId: "05b76d03-8c4b-47f4-7c20-08d9e2990812" StartGeotag: { ...

When adding new elements to an array, the IDs of all objects become identical

When running the code below: dietDay.meals.forEach((meal) => { meal.mealProducts.forEach((mealProduct) => { if ( mealProduct.product.id && this.fetchedProductIds.includes(mealProduct.p ...

Is there a way to identify a custom event in Angular 2 without relying on a template?

My Angular 2 project involves dynamically generating child components and I am trying to listen to a custom event triggered by that component. Here is the parent component responsible for generating the component and handling events: var cmpRef: Compone ...