How to prevent redirecting in Angular Js1.2

后端 未结 9 1957
情歌与酒
情歌与酒 2020-12-24 02:09

I was using AngularJs-1.0.7 and Bootstrap in my application. Recently I migrated from AngularJs-1.0.7 to AngularJs-1.2. I am using Bootstrap\'s Accordions and Tabs.

相关标签:
9条回答
  • 2020-12-24 03:01

    try data-target="#something", it works fine for me in both development and production environment.

    0 讨论(0)
  • 2020-12-24 03:02

    Just add this to your links:

    target="_self"
    

    And you're ready ;)

    0 讨论(0)
  • 2020-12-24 03:06

    I've been having this problem for a while now too, and I only just stumbled across this question (and your own answer). It turns out that you are almost correct with your solution, just a slight modification makes it work as you'd like.

    In addition to the issue you were having with tabs, I was also encountering this problem with dropdown links -- they were navigating away from the current page when clicked, instead of dropping down the menu -- and in fact, this problem is present on any link that was designed to toggle something, i.e. with the data-toggle attribute set.

    So, a slight modification to your code to check for the presence of the 'toggle' attribute solves it for me:

    app.directive('a', function() {
        return {
            restrict: 'E',
            link: function(scope, elem, attrs) {
                if(attrs.toggle){
                    elem.on('click', function(e){
                        e.preventDefault();
                    });
                }
            }
       };
    });
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题