基础Zurb DropDown不使用ng-class

时间:2015-12-11 12:12:08

标签: javascript angularjs zurb-foundation

我在我的下拉菜单中添加了ng-class,为导航点提供了不同的类。现在,当我悬停时,子项目不再起作用了(只需点击一下,子项目就会打开)。

<section class="top-bar-section para">             
      <ul class="left para">
        <li class="divider2"></li>
        <li ng-class="{'has-dropdown para divider2':navigation.type == 'Sub', 'nav_button divider2':navigation.type == 'Main'}" ng-repeat="navigation in nav.links">

          <a ng-if="navigation.type == 'Main'" href="{{navigation.link1}}" class="para">{{navigation.name}}</a>
          <a ng-if="navigation.type == 'Sub'" href="#" class="para">{{navigation.name}}</a>
          <ul ng-if="navigation.type == 'Sub'" class="dropdown">              
            <li ng-repeat="subitem in navigation.subitems"><a href="{{subitem.link}}">{{subitem.name2}}</a></li>                
          </ul> 

        </li>
      </ul>
    </section>

使用此代码可以正常工作 - 但是没有子菜单的导航点有错误的类

 <section class="top-bar-section para">             
      <ul class="left para">
        <li class="divider2"></li>
        <li class="has-dropdown divider2" ng-repeat="navigation in nav.links">

          <a ng-if="navigation.type == 'Main'" href="{{navigation.link1}}" class="para">{{navigation.name}}</a>
          <a ng-if="navigation.type == 'Sub'" href="#" class="para">{{navigation.name}}</a>
          <ul ng-if="navigation.type == 'Sub'" class="dropdown">              
            <li ng-repeat="subitem in navigation.subitems"><a href="{{subitem.link}}">{{subitem.name2}}</a></li>
            <!--<li><a href="#">Dropdown Option</a></li>      -->      
          </ul> 

        </li>
      </ul>
    </section>

这是我的JSON文件和控制器。

{
"projectTitle": "Test",
"menutitlemobile": "Menu",
"links": [
        {
        "type": "Sub",
        "name": "Menu1",
        "subitems": [{
            "name2": "Sublink1",
            "link": "http://www.google.com"
            }, 
            {
            "name2": "Sublink2",
            "link": "http://www.google.com"
            }]
        },

        {
        "type": "Main",
        "name": "Menu2",
        "link1": "http://www.google.com"
        }

]}
app.controller('NavCtrl', function($scope, $http) {

$http({
      method: 'GET',
      url: 'navigation.json',
      data: 'json',
      cache: 'false'       

      }).success(function (data) {              

          $scope.nav = data;
      })

        .error(function(data, status) {

          console.error('Repos error', status, data);
        });});

1 个答案:

答案 0 :(得分:1)

我编辑了你的plunker,看看http://plnkr.co/edit/CZiKTApTbkc3gnzy5eMl?p=preview

确保只加载一次AngularJS并在AngularJS(index.html)之前加载jQuery。

app.js中,我在加载数据后添加了$timeout。通过这种“超出范围”的行动,它可以起作用。

不好,但确实有效;)