mercredi 24 août 2016

How to use Bootstrap JavaScript plugins (dropdowns, modals) in Emberjs

I can't get Bootstrap JavaScript plugins like dropdowns and modals to work out of the box in Ember. From the command line:

ember new test-app
ember install ember-bootstrap

ember generate route test
ember generate component jquery-test

app/templates/test.hbs:



app/templates/components/jquery-test.hbs (copied from getbootstrap.com):

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

app/components/jquery-test.js:

import Ember from 'ember';

export default Ember.Component.extend({
  didInsertElement: function() {
    console.log($("button").length);
  }
});

The log prints out 4, so jQuery is installed and working, right? But while the Boostrap button is styled like a Bootstrap button should be, it doesn't function. No modal appears when I click it. Same with a dropdown menu.

  • Ember v2.7.1
  • jQuery v2.2.4
  • Bootstrap v3.3.5



Aucun commentaire:

Enregistrer un commentaire