使用AngularJS的动态菜单

时间:2014-10-29 20:15:38

标签: angularjs angularjs-ng-include ng-view

我有一个带有两个菜单的Web应用程序,一个位于顶部位置,另一个位于左侧。两个菜单'将根据记录的配置文件从DB检索选项。但是,当路线发生变化时,菜单不会呈现。

Shell.js:

<section>
 <div data-ng-include="'app/controllers/layout/header.html'"></div>
 <div id="menuDin" data-ng-include="'app/autenticado/menuDinamico.html'"></div>
 <div id="corpo" ng-view=""></div>
 <div data-ng-include="'app/controllers/layout/footer.html'"></div>
</section>

1 个答案:

答案 0 :(得分:0)

您可以使用控制器菜单中的项目创建对象,然后使用ng-repeat绘制菜单。

class MyController
constructor: ->
    @itens_menu = [ 
        {label: 'MenuA', href: 'urlA'}, 
        {label: 'MenuB', href: 'urlB'}
    ]

<ul ng-controller="MyCtrl as MyController">
        <li ng-repeat="item in MyCtrl.itens_menu">
            <a href="{{item.href}}">{{item.label}}</a>
        </li>
</ul>