Close bootstrap modal using typescript in angular 2

前端 未结 3 2170
深忆病人
深忆病人 2021-02-20 12:47

I have a button, on the click of which I am opening a bootstrap modal pop-up. The modal pop-up contains some field with a submit button. I want to close the pop-up only when I a

相关标签:
3条回答
  • 2021-02-20 13:29

    With your id="AddExpense", you can close the modal with the below code anywhere in your typescript.

    document.getElementById('AddExpense').click(); // where you want to dismiss your modal

    0 讨论(0)
  • 2021-02-20 13:31

    you can use the action on close button

    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" #closeAddExpenseModal>&times;</button>
                    <h4 class="modal-title">Add Expense</h4>
                </div>
    

    and in your controller you can add this line after the action you use

    this.closeAddExpenseModal.nativeElement.click();
    

    you will need to add this imports to your controller

    import { ViewChild, ElementRef} from '@angular/core';
    

    you will need also to define closeAddExpenseModal

    @ViewChild('closeAddExpenseModal') closeAddExpenseModal: ElementRef;
    
    0 讨论(0)
  • 2021-02-20 13:33

    I'm not sure what you really need to do but If you want to close modal with typescript you can just give an id to your html modal and call 'hide' method.

    $('#newPostModal').modal('hide');    
    

    Sorry if this isn't what you want maybe if you can explain me better I can help you

    0 讨论(0)
提交回复
热议问题