Using Bootstrap Tooltip with AngularJS

后端 未结 19 1591
抹茶落季
抹茶落季 2020-12-07 10:40

I am trying to use the Bootstrap tooltip in an app of mine. My app is using AngularJS Currently, I have the following:

19条回答
  •  星月不相逢
    2020-12-07 10:50

    If you're building an Angular app, you can use jQuery, but there is a lot of good reasons to try to avoid it in favor of more angular driven paradigms. You can continue to use the styles provided by bootstrap, but replace the jQuery plugins with native angular by using UI Bootstrap

    Include the Boostrap CSS files, Angular.js, and ui.Bootstrap.js:

    
    
    
    

    Make sure you've injected ui.bootstrap when you create your module like this:

    var app = angular.module('plunker', ['ui.bootstrap']);
    

    Then you can use angular directives instead of data attributes picked up by jQuery:

    
    

    Demo in Plunker


    Avoiding UI Bootstrap

    jQuery.min.js (94kb) + Bootstrap.min.js (32kb) is also giving you more than you need, and much more than ui-bootstrap.min.js (41kb).

    And time spent downloading the modules is only one aspect of performance.

    If you really wanted to only load the modules you needed, you can "Create a Build" and choose tooltips from the Bootstrap-UI website. Or you can explore the source code for tooltips and pick out what you need.

    Here a minified custom build with just the tooltips and templates (6kb)

提交回复
热议问题