2016-02-02 99 views
1

我正在制作一个使用AngularJS和mmenu的菜单,并且我有一些子菜单不能正确地作为子菜单。本质上,mmenu将span视为菜单,当您单击它时,它会展开(或尝试),并将标记视为链接,当您点击菜单时,菜单会关闭并尝试将您发送到链接。问题是,当我用ng-ng重复我的菜单时,我的一些项目是链接(a),有些应该有更多子菜单使它们跨越。我能想到的一些方法来解决这个问题,但我似乎无法使他们的工作,这里是我已经试过了解决方案:用跨度替换标记

  1. 使用NG-click函数来运行一个if语句,看看是否菜单被点击有一个嵌套的ul,如果它添加类mm.opened扩展子菜单,而不是跟随链接

  2. 使用函数来运行整个菜单后,它建立并找到任何<a>标记(“span”+ this.innerHTML +“/ span”)替换一个标签

  3. 寻求帮助(当前步骤)

我愿意接受任何解决方案真的,我的角度可能是错误的,其可能会导致我的所有问题,以便随时纠正我就可以了。

,因为我的菜单是由JSON文件建立,我不能导入JSON代码编辑器(据我所知)

这是我的菜单我不能附加一个工作示例:

<ul> 
    <li><a ng-href="#/home" class="menuBtn">Home</a></li> 
    <li ng-repeat="menu in menuInfo" ng-class="countDisable(menu.schematics.length, menu)"> <a class="menuBtn">ATA {{menu.ata}} - {{menu.name}}</a> 
    <ul> 
     <li ng-click="subCheck()" ng-repeat="submenu in menu.schematics"><a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name}}</a> 
     <ul> 
      <li ng-repeat="animated in submenu.subs"><a ng-href="#{{animated.view}}" ng-click="contentCtrl(animated)" class="menuBtn">{{animated.name}}</a></li> 
     </ul> 
     </li> 
    </ul> 
    </li> 
</ul> 

它看起来像这样:

Menu opened

当我点击ATA 29它扩展到这一点:

Menu opened with ATA 29 expanded

你会看到ATA 29中有4个项目,其中3个应定期环节,第一个同时拥有四个嵌套的项目,所以当我点击它,我希望它扩大就像ATA 29做,而是它认为它的一个链接,以便它这样做:

Menu opened with left hydraulic system selected

我意识到这是很难帮助没有工作的代码,但任何帮助,将不胜感激。

var app = angular.module('myApp', ['ngRoute']) 
 

 
.config(['$routeProvider', 
 
    function($routeProvider) { 
 
    //determines redirects go via shortcuts, clicking on the management icon on the main page sends the routeProvider /MG which it then uses to pull the relevant HTML file 
 
    $routeProvider 
 
     .when('/', { 
 
     controller: 'projectController', 
 
     templateUrl: './assets/html/home.html' 
 
     }) 
 
     .when('/schematicView', { 
 
     controller: 'projectController', 
 
     templateUrl: './assets/html/schematicView.html' 
 
     }) 
 
     .when('/staticView', { 
 
     controller: 'projectController', 
 
     templateUrl: './assets/html/staticView.html' 
 
     }) 
 
     .otherwise({ 
 
     controller: 'projectController', 
 
     templateUrl: './assets/html/home.html' 
 
     }) 
 
    } 
 
]); 
 

 
app.controller('projectController', function projectController($scope, $http, $rootScope, $timeout) { 
 
    // $(document).ready(function($) { 
 
    //  setTimeout(function() { 
 
    //   $("#menu").mmenu({ 
 
    //    "slidingSubmenus": false, 
 
    //    "counters": true, 
 
    //    extensions: ["multiline"], 
 
    //    offCanvas: { 
 
    //     position: "left", 
 
    //     zposition: "front" 
 
    //    } 
 
    //   }); 
 
    //  }, 100); 
 
    //  // $("#menu").click(function() { 
 
    //  //  $('.mm-opened').removeClass('mm-opened'); 
 
    //  // }); 
 
    // }); 
 

 
    $scope.menuInfo = [{ 
 
    name: "This is a span it should expand" 
 
    }]; 
 
    $scope.secMenuInfo = [{ 
 
    name: "This is an a, it should close the menu", 
 
    name2: "This is an a, but it needs to work like a span", 
 
    name3: "This is an a, it should close the menu" 
 
    }]; 
 

 

 

 
    // $scope.activeID = 'HM'; 
 
    // $scope.activePath = "Assets/images/allActive.png"; 
 

 
    // function getImgPath(item) { 
 
    //  $scope.activePath = "Assets/images/" + item.path + ""; 
 
    //  console.log($scope.activePath); 
 
    // } 
 

 
    // $("#menu em").trigger("count"); 
 

 
    $scope.setImgPath = function(btnPath) { 
 
    console.log(btnPath) 
 
    $scope.activePath = "Assets/images/" + btnPath + ""; 
 
    console.log($scope.activePath); 
 
    }; 
 
    $scope.contentCtrl = function(id) { 
 
    $scope.active = id; 
 
    console.log($scope.active); 
 
    // $scope.activeItem = item; 
 
    // getImgPath($scope.activeItem); 
 

 

 
    }; 
 
    // $scope.subCheck = function() { 
 
    //  if ($(this).children().find('mm-counter')) { 
 
    //   alert("has ul"); 
 
    //   return false; 
 
    //  } else { 
 
    //   alert("no ul"); 
 
    //   return false; 
 
    //  } 
 

 
    // }; 
 

 

 

 
}); 
 

 
app.directive("mmenu", function($timeout) { 
 
    return { 
 
    restrict: 'A', 
 
    link: function(scope, element, attrs) { 
 

 
     $timeout(function() { 
 
      $(element).mmenu({ 
 
      "slidingSubmenus": false, 
 
      "counters": true, 
 
      extensions: ["multiline"], 
 
      offCanvas: { 
 
       position: "left", 
 
       zposition: "front" 
 
      } //ends offCanvas 
 
      }); 
 

 
      $("em").each(function() { 
 
      var t = $(this).text().trim(); 
 
      if (t == "0") { 
 
       $(this).next().remove(); 
 

 
       $(this).remove(); 
 

 
      } 
 
      }); 
 
     }, 10); 
 
     } //ends link 
 
    } 
 

 
});
/* Helvetica Font */ 
 

 
@font-face { 
 
    font-family: HelveticaNeue; 
 
    src: local('0'), url('../fonts/HelveticaNeueLTStd-Lt.woff') format('woff'), url('../fonts/HelveticaNeueLTStd-Lt.otf') format('otf'); 
 
} 
 
body, 
 
html { 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    overflow: none; 
 
    color: #FFF; 
 
} 
 
body { 
 
    background: #FFFFFF; 
 
} 
 
#header { 
 
    background: #212121; 
 
    box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12); 
 
} 
 
#footer { 
 
    background: #212121; 
 
    box-shadow: 0 -1.5px 4px rgba(0, 0, 0, 0.24), 0 -1.5px 6px rgba(0, 0, 0, 0.12); 
 
} 
 
.fa { 
 
    color: #8ea5d0; 
 
} 
 
.fa:hover { 
 
    color: #627EB0; 
 
} 
 
.fa:active { 
 
    color: #415E95; 
 
} 
 
a:focus { 
 
    outline: 0 none; 
 
    color: #627EB0; 
 
    text-decoration: none; 
 
} 
 
.info_btn { 
 
    color: #FFF !important; 
 
    background-color: #8ea5d0; 
 
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.23), 0 3px 12px rgba(0, 0, 0, 0.16); 
 
} 
 
.info_btn:hover { 
 
    background-color: #627EB0; 
 
} 
 
.info_btn:active { 
 
    background-color: #415E95; 
 
    color: #FFF; 
 
    text-decoration: none; 
 
} 
 
.info_btn:hover, 
 
.info_btn:visited, 
 
.info_btn:link, 
 
.info_btn:active { 
 
    text-decoration: none; 
 
    color: #FFF; 
 
} 
 
#menu { 
 
    background: #444444; 
 
    box-shadow: 5px 0px 4px rgba(0, 0, 0, 0.3); 
 
    z-index: 10; 
 
} 
 
#menu .li { 
 
    background: #555555; 
 
} 
 
#menu > ul > li { 
 
    list-style: none; 
 
} 
 
#menu > ul { 
 
    padding: 0px; 
 
} 
 
.menuBtn { 
 
    background-color: transparent; 
 
    display: inline-flex; 
 
    cursor: pointer; 
 
    color: #ffffff; 
 
    border: #212121; 
 
    border-bottom-style: solid; 
 
    border-width: 1px; 
 
    width: 100%; 
 
    font-size: 17px; 
 
    padding: 10px 10px; 
 
    -webkit-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
    -moz-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
    -o-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
    transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
    outline: none; 
 
} 
 
.menuBtn:hover { 
 
    background-color: #333333; 
 
    outline: none; 
 
} 
 
.menuBtn:active { 
 
    position: relative; 
 
    background-color: #222222; 
 
    outline: none; 
 
} 
 
#homeContent { 
 
    color: #000000; 
 
} 
 
/* Global and Overrides */ 
 

 
#header { 
 
    height: 96px; 
 
    border: 0; 
 
    top: 0px; 
 
    width: 100%; 
 
} 
 
#content { 
 
    width: 100%; 
 
    position: fixed; 
 
    top: 96px; 
 
    bottom: 72px; 
 
} 
 
#footer { 
 
    height: 72px; 
 
    border: 0; 
 
    bottom: 0px; 
 
    position: fixed; 
 
    width: 100%; 
 
} 
 
.fa { 
 
    font-size: 36px; 
 
    cursor: pointer; 
 
    display: inline-block; 
 
    padding-top: 30px; 
 
    padding-left: 30px; 
 
} 
 
.title { 
 
    position: absolute; 
 
    right: 75px; 
 
    top: 20px; 
 
    max-width: 400px; 
 
} 
 
.info_btn { 
 
    position: absolute; 
 
    font-size: 40px; 
 
    font-weight: 400; 
 
    right: 30px; 
 
    top: 48px; 
 
    border-radius: 50px; 
 
    padding: 0 21.8px; 
 
    font-size: 20px; 
 
    line-height: 48px; 
 
    position: absolute; 
 
    top: 72px; 
 
    right: 1.6%; 
 
    z-index: 100; 
 
} 
 
/* causes the color to change when you hover over a button of class myButton */ 
 

 
.revNum { 
 
    font-size: 16px; 
 
    position: absolute; 
 
    bottom: 25px; 
 
    left: 12px; 
 
} 
 
.footer_info { 
 
    bottom: 25px; 
 
    position: absolute; 
 
    margin: 0px auto; 
 
    width: 100%; 
 
    font-size: 18px; 
 
    display: block; 
 
    text-align: center; 
 
} 
 
.logo { 
 
    height: 48px; 
 
    position: absolute; 
 
    bottom: 12px; 
 
    right: 75px; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <link href="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.6.1/css/jquery.mmenu.all.css" rel="stylesheet" /> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.6.1/js/jquery.mmenu.all.min.js"></script> 
 
    <script src="https://code.angularjs.org/1.5.0-rc.2/angular-route.js"></script> 
 
</head> 
 

 
<body ng-app="myApp" ng-controller="projectController"> 
 
    <title>{{projectInfo.title}}</title> 
 
    <div id="wrapper"> 
 
    <div id="header"> 
 

 
     <a class="fa fa-home" ng-href="#/home"></a> 
 
     <img class="title" src="assets/images/title.svg"></img> 
 
     <a href class="info_btn"><span>i</span></a> 
 
     <nav id="menu" mmenu> 
 
     <ul> 
 
      <li><a ng-href="#/home" class="menuBtn">Home</a> 
 
      </li> 
 
      <li ng-repeat="menu in menuInfo" ng-class="countDisable(menu.schematics.length, menu)"> <span class="menuBtn">ATA {{menu.ata}} - {{menu.name}}</span> 
 
      <ul> 
 
       <li ng-repeat="submenu in secMenuInfo"><a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name}}</a> 
 
       <li ng-repeat="submenu in secMenuInfo"><a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name2}}</a> 
 
       <ul> 
 
        <li ng-repeat="animated in secMenuInfo"><a ng-href="#{{animated.view}}" ng-click="contentCtrl(animated)" class="menuBtn">{{submenu.name3}}</a> 
 
        </li> 
 
       </ul> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    <div id="content"> 
 
     <a href="#menu" target="_self"><h1>HOME</h1></a> 
 
    </div> 
 
    <div id="footer"> 
 
     <div class="revNum">Revision: {{projectInfo.version}}</div> 
 
     <div class="footer_info">{{projectInfo.footer}}</div> 
 
     <img class="logo" ng-src="./assets/images/{{projectInfo.logo}}"> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

+1

你就不能写工作代码和,而不是使用JSON ,硬编码数据我nto正常变量还是我错过了什么? – zer00ne

+0

我可以,但菜单约50项,所以这是不切实际的,但它现在刚刚发生,我只需要约4项显示问题给我一秒,我会尝试写它。 –

+0

如果您需要在演示中使用JSON,请尝试以下操作:http://doc.jsfiddle.net/use/echo.html#json或使用http://plkr.co可能会更好选择。 – zer00ne

回答

1
  • 兄弟li没有关闭,并已成为一个嵌套菜单,但不正确的安装是一个子菜单。

  • li没有像我预期的那样产生span它应该有。所以我只是复制了我在顶部菜单中看到的模式,并且它工作正常。

更改此:

<li ng-repeat="submenu in secMenuInfo"> 
    <a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name}}</a> 
    <li ng-repeat="submenu in secMenuInfo"> 
    <a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name2}}</a> 

要这样:

<li ng-repeat="submenu in secMenuInfo"> 
    <a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name}}</a> 
</li> 
<li ng-repeat="submenu in secMenuInfo"> 
    <span class="menuBtn">{{submenu.name2}}</span> 

<!DOCTYPE html> 
 
<html> 
 
<meta charset="utf-8"> 
 

 
<head> 
 
    <link href="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.6.1/css/jquery.mmenu.all.css" rel="stylesheet" /> 
 

 
    <style> 
 
    /* Helvetica Font */ 
 
    @font-face { 
 
     font-family: HelveticaNeue; 
 
     src: local('0'), url('../fonts/HelveticaNeueLTStd-Lt.woff') format('woff'), url('../fonts/HelveticaNeueLTStd-Lt.otf') format('otf'); 
 
    } 
 
    body, 
 
    html { 
 
     font-family: Helvetica, Arial, sans-serif; 
 
     overflow: none; 
 
     color: #FFF; 
 
    } 
 
    body { 
 
     background: #FFFFFF; 
 
    } 
 
    #header { 
 
     background: #212121; 
 
     box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12); 
 
    } 
 
    #footer { 
 
     background: #212121; 
 
     box-shadow: 0 -1.5px 4px rgba(0, 0, 0, 0.24), 0 -1.5px 6px rgba(0, 0, 0, 0.12); 
 
    } 
 
    .fa { 
 
     color: #8ea5d0; 
 
    } 
 
    .fa:hover { 
 
     color: #627EB0; 
 
    } 
 
    .fa:active { 
 
     color: #415E95; 
 
    } 
 
    a:focus { 
 
     outline: 0 none; 
 
     color: #627EB0; 
 
     text-decoration: none; 
 
    } 
 
    .info_btn { 
 
     color: #FFF !important; 
 
     background-color: #8ea5d0; 
 
     box-shadow: 0 3px 12px rgba(0, 0, 0, 0.23), 0 3px 12px rgba(0, 0, 0, 0.16); 
 
    } 
 
    .info_btn:hover { 
 
     background-color: #627EB0; 
 
    } 
 
    .info_btn:active { 
 
     background-color: #415E95; 
 
     color: #FFF; 
 
     text-decoration: none; 
 
    } 
 
    .info_btn:hover, 
 
    .info_btn:visited, 
 
    .info_btn:link, 
 
    .info_btn:active { 
 
     text-decoration: none; 
 
     color: #FFF; 
 
    } 
 
    #menu { 
 
     background: #444444; 
 
     box-shadow: 5px 0px 4px rgba(0, 0, 0, 0.3); 
 
     z-index: 10; 
 
    } 
 
    #menu .li { 
 
     background: #555555; 
 
    } 
 
    #menu > ul > li { 
 
     list-style: none; 
 
    } 
 
    #menu > ul { 
 
     padding: 0px; 
 
    } 
 
    .menuBtn { 
 
     background-color: transparent; 
 
     display: inline-flex; 
 
     cursor: pointer; 
 
     color: #ffffff; 
 
     border: #212121; 
 
     border-bottom-style: solid; 
 
     border-width: 1px; 
 
     width: 100%; 
 
     font-size: 17px; 
 
     padding: 10px 10px; 
 
     -webkit-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
     -moz-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
     -o-transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
     transition: color .25s linear, background-color .25s ease-in-out, border-color .25s ease-in-out; 
 
     outline: none; 
 
    } 
 
    .menuBtn:hover { 
 
     background-color: #333333; 
 
     outline: none; 
 
    } 
 
    .menuBtn:active { 
 
     position: relative; 
 
     background-color: #222222; 
 
     outline: none; 
 
    } 
 
    #homeContent { 
 
     color: #000000; 
 
    } 
 
    /* Global and Overrides */ 
 
    #header { 
 
     height: 96px; 
 
     border: 0; 
 
     top: 0px; 
 
     width: 100%; 
 
    } 
 
    #content { 
 
     width: 100%; 
 
     position: fixed; 
 
     top: 96px; 
 
     bottom: 72px; 
 
    } 
 
    #footer { 
 
     height: 72px; 
 
     border: 0; 
 
     bottom: 0px; 
 
     position: fixed; 
 
     width: 100%; 
 
    } 
 
    .fa { 
 
     font-size: 36px; 
 
     cursor: pointer; 
 
     display: inline-block; 
 
     padding-top: 30px; 
 
     padding-left: 30px; 
 
    } 
 
    .title { 
 
     position: absolute; 
 
     right: 75px; 
 
     top: 20px; 
 
     max-width: 400px; 
 
    } 
 
    .info_btn { 
 
     position: absolute; 
 
     font-size: 40px; 
 
     font-weight: 400; 
 
     right: 30px; 
 
     top: 48px; 
 
     border-radius: 50px; 
 
     padding: 0 21.8px; 
 
     font-size: 20px; 
 
     line-height: 48px; 
 
     position: absolute; 
 
     top: 72px; 
 
     right: 1.6%; 
 
     z-index: 100; 
 
    } 
 
    /* causes the color to change when you hover over a button of class myButton */ 
 
    .revNum { 
 
     font-size: 16px; 
 
     position: absolute; 
 
     bottom: 25px; 
 
     left: 12px; 
 
    } 
 
    .footer_info { 
 
     bottom: 25px; 
 
     position: absolute; 
 
     margin: 0px auto; 
 
     width: 100%; 
 
     font-size: 18px; 
 
     display: block; 
 
     text-align: center; 
 
    } 
 
    .logo { 
 
     height: 48px; 
 
     position: absolute; 
 
     bottom: 12px; 
 
     right: 75px; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body ng-app="myApp" ng-controller="projectController"> 
 
    <title>{{projectInfo.title}}</title> 
 
    <div id="wrapper"> 
 
    <div id="header"> 
 

 
     <a class="fa fa-home" ng-href="#/home"></a> 
 
     <img class="title" src="assets/images/title.svg"></img> 
 
     <a href class="info_btn"><span>i</span></a> 
 
     <nav id="menu" mmenu> 
 
     <ul> 
 
      <li><a ng-href="#/home" class="menuBtn">Home</a> 
 
      </li> 
 
      <li ng-repeat="menu in menuInfo" ng-class="countDisable(menu.schematics.length, menu)"> <span class="menuBtn">ATA {{menu.ata}} - {{menu.name}}</span> 
 
      <ul> 
 
       <li ng-repeat="submenu in secMenuInfo"><a ng-href="#{{submenu.view}}" class="menuBtn">{{submenu.name}}</a> 
 
       </li> 
 
       <li ng-repeat="submenu in secMenuInfo"><span class="menuBtn">{{submenu.name2}}</span> 
 
       <ul> 
 
        <li ng-repeat="animated in secMenuInfo"><a ng-href="#{{animated.view}}" ng-click="contentCtrl(animated)" class="menuBtn">{{submenu.name3}}</a> 
 
        </li> 
 
       </ul> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    <div id="content"> 
 
     <a href="#menu" target="_self"><h1>HOME</h1></a> 
 
    </div> 
 
    <div id="footer"> 
 
     <div class="revNum">Revision: {{projectInfo.version}}</div> 
 
     <div class="footer_info">{{projectInfo.footer}}</div> 
 
     <img class="logo" ng-src="./assets/images/{{projectInfo.logo}}"> 
 
    </div> 
 
    </div> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.6.1/js/jquery.mmenu.all.min.js"></script> 
 
    <script src="https://code.angularjs.org/1.5.0-rc.2/angular-route.js"></script> 
 
    <script> 
 
    var app = angular.module('myApp', ['ngRoute']) 
 

 
    .config(['$routeProvider', 
 
     function($routeProvider) { 
 
     //determines redirects go via shortcuts, clicking on the management icon on the main page sends the routeProvider /MG which it then uses to pull the relevant HTML file 
 
     $routeProvider 
 
      .when('/', { 
 
      controller: 'projectController', 
 
      templateUrl: './assets/html/home.html' 
 
      }) 
 
      .when('/schematicView', { 
 
      controller: 'projectController', 
 
      templateUrl: './assets/html/schematicView.html' 
 
      }) 
 
      .when('/staticView', { 
 
      controller: 'projectController', 
 
      templateUrl: './assets/html/staticView.html' 
 
      }) 
 
      .otherwise({ 
 
      controller: 'projectController', 
 
      templateUrl: './assets/html/home.html' 
 
      }) 
 
     } 
 
    ]); 
 

 
    app.controller('projectController', function projectController($scope, $http, $rootScope, $timeout) { 
 
     // $(document).ready(function($) { 
 
     //  setTimeout(function() { 
 
     //   $("#menu").mmenu({ 
 
     //    "slidingSubmenus": false, 
 
     //    "counters": true, 
 
     //    extensions: ["multiline"], 
 
     //    offCanvas: { 
 
     //     position: "left", 
 
     //     zposition: "front" 
 
     //    } 
 
     //   }); 
 
     //  }, 100); 
 
     //  // $("#menu").click(function() { 
 
     //  //  $('.mm-opened').removeClass('mm-opened'); 
 
     //  // }); 
 
     // }); 
 

 
     $scope.menuInfo = [{ 
 
     name: "This is a span it should expand" 
 
     }]; 
 
     $scope.secMenuInfo = [{ 
 
     name: "This is an a, it should close the menu", 
 
     name2: "This is an a, but it needs to work like a span", 
 
     name3: "This is an a, it should close the menu" 
 
     }]; 
 

 

 

 
     // $scope.activeID = 'HM'; 
 
     // $scope.activePath = "Assets/images/allActive.png"; 
 

 
     // function getImgPath(item) { 
 
     //  $scope.activePath = "Assets/images/" + item.path + ""; 
 
     //  console.log($scope.activePath); 
 
     // } 
 

 
     // $("#menu em").trigger("count"); 
 

 
     $scope.setImgPath = function(btnPath) { 
 
     console.log(btnPath) 
 
     $scope.activePath = "Assets/images/" + btnPath + ""; 
 
     console.log($scope.activePath); 
 
     }; 
 
     $scope.contentCtrl = function(id) { 
 
     $scope.active = id; 
 
     console.log($scope.active); 
 
     // $scope.activeItem = item; 
 
     // getImgPath($scope.activeItem); 
 

 

 
     }; 
 
     // $scope.subCheck = function() { 
 
     //  if ($(this).children().find('mm-counter')) { 
 
     //   alert("has ul"); 
 
     //   return false; 
 
     //  } else { 
 
     //   alert("no ul"); 
 
     //   return false; 
 
     //  } 
 

 
     // }; 
 

 

 

 
    }); 
 

 
    app.directive("mmenu", function($timeout) { 
 
     return { 
 
     restrict: 'A', 
 
     link: function(scope, element, attrs) { 
 

 
      $timeout(function() { 
 
       $(element).mmenu({ 
 
       "slidingSubmenus": false, 
 
       "counters": true, 
 
       extensions: ["multiline"], 
 
       offCanvas: { 
 
        position: "left", 
 
        zposition: "front" 
 
       } //ends offCanvas 
 
       }); 
 

 
       $("em").each(function() { 
 
       var t = $(this).text().trim(); 
 
       if (t == "0") { 
 
        $(this).next().remove(); 
 

 
        $(this).remove(); 
 

 
       } 
 
       }); 
 
      }, 10); 
 
      } //ends link 
 
     } 
 

 
    }); 
 
    </script> 
 
</body> 
 

 
</html>

0

在不超通读问题道歉,这是一个有点长......

这听起来像你想<span>标签,以取代所有<a>标签。一种解决方案是向控制器添加一个函数,将锚文本取出并进行替换,然后通过函数运行ng-repeat中的变量。

$scope.replaceAnchors = function(item) { 
    var matches = /<a\s+[^>]*href="([^"]*)"[^>]*>(.*)<\/a>/i.exec(str); 
    return '<span>' + matches[2] + '</span>'; 
} 

而且在你的模板:

{{replaceAnchors(YOUR.MENU.VARIABLE)}}