web-dev-qa-db-fra.com

le modal ng-bootstrap ne ferme pas après un clic croisé

j'utilise la fenêtre contextuelle modale de ng-bootstrap, et elle ne ferme pas en cliquant sur le bouton en croix. 

Ceci est la balise <a> qui déclenche le popup - 

<div class="actions padding-zero">
    <a href="javascript:void(0);" (click)="openFilter()" class="icon configure-columns-icon">
        <span class="control-label">Configure Columns</span>
    </a>
</div>

Modal - 

<ng-template #filterForm let-modal>
    <div class="TitlePanel">
    Configure Columns                       
    <button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
    X
    </button>
    </div>
    <div class="modal-body">
      Body
    </div>                   
</ng-template>

fichier composant.ts - 

export class NgbdModalContent {
    @Input() name;
    constructor(public activeModal: NgbActiveModal) { }
}


@Component({
    selector: 'app-modals',
    templateUrl: './modals.component.html',
    styleUrls: ['./modals.component.scss'],
    encapsulation: ViewEncapsulation.None,
})

export class ModalsComponent {

    closeResult: string;

    constructor(private modalService: NgbModal) { }

    // Open default modal
    open(content) {
        this.modalService.open(content).result.then((result) => {
            this.closeResult = `Closed with: ${result}`;
        }, (reason) => {
            this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
        });
    }

    // This function is used in open
    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}`;
        }
    }

    // Open modal with dark section
    openModal(customContent) {
        this.modalService.open(customContent, { windowClass: 'dark-modal' });
    }

    // Open content with dark section
    openContent() {
        const modalRef = this.modalService.open(NgbdModalContent);
        modalRef.componentInstance.name = 'World';
    }
}

En outre, je reçois cette erreur dans la console lorsque je clique sur le bouton de fermeture - "Impossible de lire la propriété 'rejeter' des indéfinis"

 enter image description here

3
Sagar Raj

Après quelques recherches et ces changements, cela a fonctionné.

<ng-template #filterForm let-d="dismiss">
    <div class="TitlePanel">
        Configure Columns                       
        <button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
        X
        </button>
    </div>
    <div class="modal-body">
       Body
    </div>                   
</ng-template>
8
Sagar Raj

Vous utilisez modal mais vous vous injectez activeModal. Mettez à jour le code html à ceci:

<ng-template #filterForm let-modal>
    <div class="TitlePanel">
    Configure Columns                       
    <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
    X
    </button>
    </div>
    <div class="modal-body">
      Body
    </div>                   
</ng-template>
1
Gobli
(click)="modal.dismiss('Cross click')"

doit être changé pour 

(click)="activeModal.dismiss('Cross click')"

parce que tu donnes

public activeModal: NgbActiveModal
1
Franklin Pious
[solution by   using modal reference][1]

[1]: Angular 2 ng-bootstrap close ModalCela fonctionne

0
Rinold