简体   繁体   English

Javascript ng-href无法在ng-repeat中工作

[英]Javascript ng-href not working in ng-repeat

I have an accordion wich is opening when I click on it . 单击时,我手风琴正在打开。 Everything is working just fine when I don't use ng-repeat , but once I use it , it will not go to my href adress , and will go to /home. 当我不使用ng-repeat时,一切工作都很好,但是一旦使用它,它就不会进入我的href地址,而会进入/ home。 Here is my HTML code: 这是我的HTML代码:

   <div class="accordion" ng-repeat="department in allDepartments">
    <div class="accordion-section">
        <a class="accordion-section-title" ng-href="#{{department.name}}"  >{{department.name}} </a>

        <div ng-attr-id="{{department.name}}" class="accordion-section-content" target="_self">
            <p>Mauris interdum fringilla augue vitae tincidunt. Curabitur vitae tortor id eros euismod ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent nulla mi, rutrum ut feugiat at, vestibulum ut neque? Cras tincidunt enim vel aliquet facilisis. Duis congue ullamcorper vehicula. Proin nunc lacus, semper sit amet elit sit amet, aliquet pulvinar erat. Nunc pretium quis sapien eu rhoncus. Suspendisse ornare gravida mi, et placerat tellus tempor vitae.</p>
        </div><!--end .accordion-section-content-->
    </div><!--end .accordion-section-->
</div><!--end .accordion-->

And here is my JS code : 这是我的JS代码:

$(document).ready(function() {
        function close_accordion_section() {
            $('.accordion .accordion-section-title').removeClass('active');
            $('.accordion .accordion-section-content').slideUp(300).removeClass('open');
        }

        $('.accordion-section-title').click(function(e) {
            // Grab current anchor value
            var currentAttrValue = $(this).attr('href');

            if($(e.target).is('.active')) {
                close_accordion_section();
            }else {
                close_accordion_section();

                // Add active class to section title
                $(this).addClass('active');
                // Open up the hidden content panel
                $('.accordion ' + currentAttrValue).slideDown(300).addClass('open');
            }

            e.preventDefault();
        });
    });

And finally my css code : 最后是我的CSS代码:

/*----- Accordion -----*/
.accordion, .accordion * {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}

.accordion {
overflow:hidden;
box-shadow:0px 1px 3px rgba(0,0,0,0.25);
border-radius:3px;
background:#f7f7f7;
}

/*----- Section Titles -----*/
.accordion-section-title {
width:100%;
padding:15px;
display:inline-block;
border-bottom:1px solid #1a1a1a;
background:#333;
transition:all linear 0.15s;
/* Type */
font-size:1.200em;
text-shadow:0px 1px 0px #1a1a1a;
color:#fff;
}

.accordion-section-title.active, .accordion-section-title:hover {
background:#4c4c4c;
/* Type */
text-decoration:none;
}

.accordion-section:last-child .accordion-section-title {
border-bottom:none;
}

/*----- Section Content -----*/
.accordion-section-content {
padding:15px;
display:none;
}

You are mixing jQuery and AngularJs (Bad pratice)... However in AngularJs the hash character ('#') is used to change view (yoursite/#/view1) while in pure html it's used to forward the page in the point where there's the id (yoursite/#id) 您正在混合使用jQuery和AngularJs(错误实践)...但是,在AngularJs中,哈希字符('#')用于更改视图(yoursite /#/ view1),而在纯HTML中,它用于将页面转发到有ID(您的网站/#id)

this is why your browser redirect you on your homepage 这就是为什么您的浏览器会在首页上重定向您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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