Angular 2 - Open/Close default bootstrap modal

前端 未结 5 1788
悲哀的现实
悲哀的现实 2020-12-30 02:15

I do not want to use angular2-bootstrap or ng2-bs3-modal as suggested in the questions/answers Angular 2 Bootstrap Modal and Angular 2.0 and Modal Dialog

Now. I kno

5条回答
  •  生来不讨喜
    2020-12-30 02:50

    if your modal has a cancel button (Otherwise create a hidden close button). You can simulate the click event on this button so that your form is closed. Iin your component add a ViewChild

    export class HelloComponent implements OnInit {
    
    @ViewChild('fileInput') fileInput:ElementRef;
    

    in your close button add #fileInput

    
    

    When you want to close the modal programmatically trigger an click event on the close button

    this.fileInput.nativeElement.click();
    

    To open you can use the same idea

提交回复
热议问题