How to use code to open a modal in Angular 2?

前端 未结 14 2981
天涯浪人
天涯浪人 2020-12-05 04:34

Usually we use data-target=\"#myModal\" in the

14条回答
  •  失恋的感觉
    2020-12-05 05:10

    Easy way to achieve this in angular 2 or 4 (Assuming that you are using bootstrap 4)

    Component.html

    
    
    

    Component.ts

    import {Component, OnInit, ViewChild} from '@angular/core';
    
    @ViewChild('myModal') myModal;
    
    openModel() {
      this.myModal.nativeElement.className = 'modal fade show';
    }
    closeModel() {
       this.myModal.nativeElement.className = 'modal hide';
    }
    

提交回复
热议问题