Not working modal pop up button in angular 6

10,399
1) Install bootstrap using npm

npm install bootstrap --save

2) Install JQUERY

npm install jquery --save

open .angular-cli.json this file are available on you angular directory open that file and add the path of bootstrap css, see the below example

"styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
           ],

    //than add div for model in your component html like below

    <div id="myModal" class="modal fade" role="dialog"><div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
<button  type="button" (click)="getUserDetails()" class="btn " data-toggle="modal" data-target="#myModal">
  Detail </button>
Share:
10,399

Related videos on Youtube

a bc
Author by

a bc

Updated on June 04, 2022

Comments

  • a bc
    a bc almost 2 years
    <div class="modal fade" id="getUserDetails" tabindex="-1" role="dialog" aria-labelledby="getUserDetails">
      <div class="modal-dialog container2" role="document">
        test
      </div>
    </div>
    
    
    <button (click)="getUserDetails(participant.userId)" type="button" class="btn " data-toggle="modal" data-target="#getUserDetails">
      Detail
    </button>
    

    My angular version 6

    bootstrap version 4

    button (click)="getUserDetails(participant.userId)" is normally working. But data-target (bound modal fade) is not visible.

    I tried to set up JQuery and import JQuery to angular.json. still it's not works please help me

  • mittal bhatt
    mittal bhatt almost 6 years
    you need to add <div class="modal-content"> and <div class="modal-body">after <div class="modal-dialog container2" role="document"> like below <div class="modal-dialog container2" role="document"> <div class="modal-content"> <div class="modal-body"> test </div> </div> </div>
  • a bc
    a bc almost 6 years
    I guess this problem by conflict between Bootstrap css setting and my component css file setting How I set my component setiing ignored Bootstrap css setting
  • mittal bhatt
    mittal bhatt almost 6 years
    declare your bootstrap css in angualr.json file than its not conflict with other css
  • a bc
    a bc almost 6 years
    I use style in github.com/start-angular/SB-Admin-BS4-Angular-6/tree/master/‌​src. no import node_modules/bootstrap/dist/css/bootstrap.min.css. bit if the code is imported in angular.json result is same...