0

I am trying to make a bootstrap single level menu using angularJS. It already works with js and html when the <li> is dynamically built.

Now I am trying to use AngularJS.

Suppose I have a JS object which has Cust and then orders inside. How can I make a list menu

<ul>
  <li ng-repeat="cust in customers">
    <p>{{cust.name}}</p>
    <li ng-repeat="order in cust.orders">
      <p>{{order.desc}}</p>
    </li>
  </li>
<ul>

This doesn't load properly (overlapping items) as the first li can't be closed.

1
  • You last <ul> is unclosed as well Commented Aug 1, 2013 at 17:50

2 Answers 2

2

Christopher is right, you can't do without <ul>.

I think you can do this to have a one level menu :

<ul>
    <li ng-repeat="cust in customers">
        <p>{{cust.name}}</p>
        <div ng-repeat="order in cust.orders">
            <p>{{order.desc}}</p>
        </div>
   </li> 
<ul>

And perhaps play with CSS to style in the way you want.

Or this, too :

<ul>
    <li ng-repeat="cust in customers">
        <p>{{cust.name}}</p>
        <p ng-repeat="order in cust.orders">
            {{order.desc}}
        </p>
   </li> 
<ul>
Sign up to request clarification or add additional context in comments.

Comments

2

That's invalid markup, you're missing a ul

Try

<ul>
  <li ng-repeat="cust in customers">
    <p>{{cust.name}}</p>
    <ul>
        <li ng-repeat="order in cust.orders">
          <p>{{order.desc}}</p>
        </li>
    </ul>
  </li>
</ul>

That should render it correctly, your bindings are correct.

2 Comments

This is what I don't want to do. My question is : how I can make it a menu of one level only. Is there a way to do this ? <ul> <li ng-repeat="cust in customers"> <p>{{cust.name}}</p> </li> <li ng-repeat="order in cust.orders"> <p>{{order.desc}}</p> </li> <ul>
I guess I don't understand what you're trying to do. You can have both li's direct children of the ul repeat, but not am li inside. You can change the second ng-repeat to use a div or something instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.