javascript - Dynamic Angular.js menu -
i trying build dynamic menu using anuglar.js , bootstrap. menu needs have dropdown ability. i've gotten basic menu down i'm trying add dropdown link , can't options generate correctly.
i have variable menu items so:
var nav = [ { display: 'home', link: '#/', drop: false, }, { display: 'categories', link: '#/', drop: true, sub: [ { display: 'sub 1', link: '#/' }, { display: 'sub 2', link: '#/' }, { display: 'sub 3', link: '#/' } ] } ];
i want dropdown menu generate of sub
items when drop
true
, regular menu item when false
.
this html far:
<ul class="nav navbar-nav"> <li class="dropdown" ng-repeat="nav in nav" ng-if="drop == nav.drop"> <a class="dropdown-toggle" data-toggle="dropdown" href="{{nav.link}}"> {{nav.display}} <b class="caret"></b> </a> <ul class="dropdown-menu"> <li ng-repeat="sub in nav.sub"><a href="{{sub.link}}">{{sub.display}}</a></li> </ul> </li> <li ng-if="drop != nav.drop" ng-repeat="nav in nav"> <a href="{{nav.link}}">{{nav.display}}</a> </li> </ul>
right generating normal link.
i think ng-if
problem. change this:
ng-if="drop == nav.drop"
to this:
ng-if="nav.drop"
and this:
ng-if="drop != nav.drop"
to this:
ng-if="!nav.drop"
incidentally, agree commenter ng-repeat="nav in nav"
confusing.
edit:
how 1 list instead of two:
<ul class="nav navbar-nav"> <li class="dropdown" ng-repeat="nav in nav"> <a ng-if="!nav.drop" href="{{nav.link}}">{{nav.display}}</a> <a ng-if="nav.drop" class="dropdown-toggle" data-toggle="dropdown" href="{{nav.link}}"> {{nav.display}} <b class="caret"></b> </a> <ul ng-if="nav.drop" class="dropdown-menu"> <li ng-repeat="sub in nav.sub"><a href="{{sub.link}}">{{sub.display}}</a></li> </ul> </li> </ul>
Comments
Post a Comment