【问题标题】:adding bootstrap active class in navigation with codeigniter and Angularjs使用 codeigniter 和 Angularjs 在导航中添加引导活动类
【发布时间】:2017-04-11 04:10:29
【问题描述】:

我想将引导活动类添加到我的导航中。在导航中我使用了 href

这是codeigniter链接意味着将重定向到新页面,并且活动类将通过angularjs添加到其中。我的导航是

<ul>
<li ng-class="{active:isActive('/c_home')}"><a href="<?php echo base_url();?>c_home>home</a></li>
<li ng-class="{active:isActive('/c_contact')}" ><a href="<?php echo base_url();?>c_contact>contact</a></li>
</ul>

而我的 js 函数没有应用程序和控制器只使用函数

$scope.isActive = function(currentLocation){

return currentLocation === $location.path();

}

我的问题是第二次点击后活动类应用。我的意思是说第一次点击不起作用。

我猜想在加载 codeigniter url 之前调用 angularjs 函数

【问题讨论】:

    标签: angularjs codeigniter


    【解决方案1】:

    我没有在 Angularjs 中使用 CI,但是当我想将一个活动类放到我的导航栏中的链接时,这就是我使用的:

    $(document).ready(function () {
        if(window.location.href.indexOf("part_of_uri") > -1) {
           $("#menu_item_a").removeClass('active');
           $("#menu_item_b").addClass('active');
        } else if (window.location.href.indexOf("another_part_of_uri") > -1) {
            $("#menu_item_b").removeClass('active');
            $("#menu_item_a").addClass('active');
        } ... // and goes on
    });
    

    这样做的目的是,如果字符串 part_of_uri 与您的 url 片段匹配,则从 menu_item_a 中删除活动类并将其应用于 menu_item_b 等等,您需要尽可能多的菜单项。

    希望能有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      相关资源
      最近更新 更多