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

Investigating TypeScript Bugs in Visual Studio Code

As I navigate through various sources, I notice that there is a plethora of information available on older versions of VSCode (v1.16.1 - the most recent version at the time of writing) or deprecated attributes in the launch.json file. I have experimented ...

Tips for modifying the toastr message width in Angular

I am currently using ngx-toastr from npm for toastr message notifications in my Angular 9 stack. Is there a way to adjust the max-width of the messages, as they are wrapping the text? this.toastrService.error( 'This is an error message to b ...

Learn the process of importing third-party vendor node modules along with their sub dependencies in Angular 2 using angular-cli

Looking to load a more complex node module in an Angular 2 project bootstrapped with angular-cli? The wiki has instructions for loading a single node module, but what about modules with multiple dependencies like angular2-apollo? For example, angular2-apo ...

What is the step-by-step process for implementing tooltips in Ant Design Menu after version 4.20.0?

According to the Ant Design documentation: Starting from version 4.20.0, a simpler usage <Menu items={[...]} /> is provided with enhanced performance and the ability to write cleaner code in your applications. The old usage will be deprecated in th ...

Data not being retrieved by HTTP GET request

I encountered an issue with my API where I made three Get requests using the same function but different URLs to differentiate between them. However, even though the provider returns the data in steps, the page response function does not receive it and sho ...

What are some ways to control providers in targeted tests using ng-mocks?

I recently started utilizing ng-mocks to streamline my testing process. However, I am struggling to figure out how to modify the value of mock providers in nested describes/tests after MockBuilder/MockRender have already been defined. Specifically, my que ...

Tips for sending arguments to translations

I am currently implementing vuejs 3 using TS. I have set up my translation files in TypeScript as shown below: index.ts: export default { 'example': 'example', } To use the translations, I simply do: {{ $t('example') }} N ...

Enhanced assistance for optional chaining operator available in Visual Studio Code

React Native 0.56 now supports the Optional Chaining Operator with ?. Unfortunately, the latest stable version of VS Code does not recognize this syntax and displays a TypeScript validation error: [ts] Expression expected. No compile-time or eslint erro ...

Can we handle optional properties that are contingent on a boolean in the type?

My current scenario involves a server response containing a boolean indicating success and optional data or error information. type ServerResponse = { success: boolean; data?: { [key: string]: string }; err?: { code: number, message: string }; } Dea ...

Tips for accurately inputting a global object with an index

I'm in the process of converting a large monolithic JavaScript application to TypeScript and am facing an issue regarding typing a specific module. I am seeking guidance on how to approach this particular problem. It's important to note that I d ...

The user interface design transforms as a PDF file is being generated through html2pdf

I am experiencing an unusual problem while using html2pdf to convert an HTML page to a PDF file and download it. The conversion process is successful and the PDF file is downloaded without any issues. However, when I click on a button to generate the file, ...

Is there a way to reveal only the version information from the package.json file in an Angular 17 project?

Is there a secure way to extract and display only the version from a package.json file on the UI of a web application without exposing the rest of its contents? I am currently using the following structure in my package.json: { "name": "exa ...

NGRX 8 reducer now outputting an Object rather than an Array

I am facing an issue where the data returned from the reducer is an object instead of an array. Despite trying to return action.recentSearches, it doesn't seem to work as expected. The data being returned looks like this: { "loading": false, "recent ...

Problem with Angular2 app routing on the github pages

As a newcomer to Angular2, I am in the process of setting up a small Angular2 app (helloworld) on github pages to kickstart my project. I initially created ng2-lite with the help of angular-cli, and it is now hosted at this site. The deployment was handle ...

Adding images to your SVG using Bobril is a simple process that can add visual

I have been attempting to insert an image into an SVG using Bobril, but the following code is not functioning as expected: { tag: 'svg', children: { tag: 'image', attrs: { 'xlink:href': &ap ...

By default in Angular 2, radio buttons will not be checked

Here is the HTML code snippet : <div class="form-group"> <div class="form-text">Question about Email and Phone Details?</div> <div> <input type="radio" value="1" [formControl]="si ...

Creating an if statement based on the currently chosen option

My angular JS page includes a drop-down list: <div class="col-md-4 fieldMargin"> <div class="dropdownIcon"> <select name="actions" id="actions" ...

Angular2 Cascading Animations

I have been working on implementing cascaded animations for a list of elements. Although I successfully applied the state triggers, following the guidelines in the documentation, I am encountering an issue where all element states are being applied simult ...

Are you delving into the realm of reduce functions in order to grasp the intric

Currently following this particular tutorial where they utilize the reduce method to transform an Array<Student> into a { [key: string]: Array<string | number> }. The tutorial includes this expression that caught my attention. It's quite n ...

assign data points to Chart.js

I have written a piece of code that counts the occurrences of each date in an array: let month = []; let current; let count = 0; chartDates = chartDates.sort() for (var i = 0; i < chartDates.length; i++) { month.push(chartDates[i].split('-&ap ...