简体   繁体   中英

Bootstrap Tapdrop jQuery in angular.js controller

I saw Bootstrap Tapdrop library and it is perfect for dropdown in my responsive tabs. My app works with angular.js, but add the bootstrap-tapdrop.js in my index.html .

I want to call:

$('.nav-tabs').tabdrop({align:'left'});

into my angularjs app but nothing works. However, when I call this from chrome console works ok.

How can I add this sentence jQuery angular.js my driver? is there anyway? or..how can I use this library from angular.js? I have sought similar things in angular but can not find.

Thanks

You have to create a directive in order to use jQuery plugins or whenever you want to attach client side behavior to elements using jQuery or any third party plugins.

Try something like this.

angular.module('main')
  .directive('my-tabs-directive', [ function ($timeout, $sce) {
      return {
        restrict: 'E',
        link: function (scope, element, attrs) {
          //Write any plugin logic here
          element.tabdrop({align: 'left'});
        },
        templateUrl: 'passYourTemplateUrl'//You can also use inline template
      };
    }
  ]);

You can understand more about angularJs directive here https://docs.angularjs.org/guide/directive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM