角度分量不会保留

时间:2017-10-18 00:07:45

标签: javascript angularjs web

我有一个菜单组件:

    <nav class="mxmls-mobile-nav"> 
  <button class="mobile-menu-btn visible-xs visible-sm " ng-click="asideVm.open = false">
    <i class="ion-android-close"></i>
  </button>
</nav>
<a class="navbar-brand visible-xs visible-sm " ui-sref="layout.dashboard">
 <img src="assets/images/logo/mxmls-logo.png" alt="" height="30" >
</a>
<nav class="mxmls-main-menu">
  <ul class="mxmls-menu">
    <li ui-sref-active="active" class="{{item.extraClass}}" ng-repeat="item in asideVm.menuItems" ng-click="asideVm.activateSubmenuParent(item)" ng-class="{'close-menu':item.submenu, 'active': item.activateSubmenu || item.active}">
      <a ui-sref="{{item.ui_state}}" ng-if="item.ui_state" ng-click="asideVm.changeType(); asideVm.removeSubmenuActiveState();" ng-bind-html="item.name">
        <!-- <i class="fa {{item.icon}} pull-left"></i> -->
        <!-- <span class="selected"></span> -->
      </a>
      <a ui-sref-active="active" ng-if="!item.ui_state;" ng-click="item.submenu = !item.submenu;asideVm.saveStatusMenu()">
        <!-- <i class="fa {{item.icon}} pull-left"></i> -->{{item.name}}
        <span class="icon-arrow pull-right"></span>
      </a>
      <ul class="mxmls-submenu" ng-if="item.sections" ng-class="{'hide':item.submenu}">
        <li ui-sref-active="active" ng-repeat="subItem in item.sections" ng-class="{'active': subItem.active}">
          <a ui-sref="{{subItem.ui_state}}" ng-click="asideVm.changeType(); asideVm.activateSubmenuParent(subItem);">
           <!-- <i class="fa {{item.icon}} pull-left"></i> -->{{subItem.name}}
           <!-- <span class="selected"></span> -->
         </a>
       </li>
     </ul>
   </li>
 </ul>
</nav> 

asideVm.menuItems中的元素具有attrib“active”,用于在clic上使用“active”类(此处一切正常)时将其聚焦。 但是,当点击如下链接时:

<a href="/acm/venta/search" class="btn btn-base ng-binding" ui-sref="layout.acm.state.search({type:'venta'})">Iniciar análisis</a>

菜单中的“活动”类丢失了。我需要帮助:/

数组“asideVm.menuItems”存储在cookie中(而attrib“也是”活动的“),我在页面加载时得到它。

1 个答案:

答案 0 :(得分:0)

我找到答案XD

首先,如果正在初始化,则初始化一个变量for flag:

vm.initialize = true;

之后:使用&#34; scope.watch&#34;检查,如果&#34; url / location&#34;改变了;如果那并且没有初始化,请使用函数&#34; $ state.reload()&#34;用于刷新组件/指令/控件:

 $scope.$watch(function(){
    return $location.path();
      }, function(value){
        if(!vm.initialize)
        {
          console.log(value);
          $state.reload();
        }
        else
        {
          vm.initialize=false;
        }
      });