Bootstrap carousel not working with angularjs

后端 未结 9 666
执笔经年
执笔经年 2020-12-03 04:55

I want to use bootstrap carousel along with angular js to display images in carousel content. But, when the navigation links clicked, it displays blank page.

My code

9条回答
  •  我在风中等你
    2020-12-03 05:11

    As mentioned, the issue is with AngularJS and ngRoute intercepting the a-link clicks. I had this problem but did not want to use Angular UI Bootstrap (as described in other answers).

    So, I changed the .carousel-control elements from links (a tags) to spans.

    
        
    
    
        
    
    

    Then, I added an event handler as follows...

      $('.carousel').carousel({
                    interval: 5000,
                    pause: "hover",
                    wrap: true
                })
                .on('click', '.carousel-control', handle_nav);
    
      var handle_nav = function(e) {
            e.preventDefault();
            var nav = $(this);
            nav.parents('.carousel').carousel(nav.data('slide'));
      }
    

    Hope this helps...

提交回复
热议问题