2

I'm new at AngularJS and I want to design menu and submenus as shown in following Image -

Required Menu

I have already created menus in AngularJS as showing in following image- Same code also added in http://jsfiddle.net/ashokyede20/pLnvsnLa/46/ enter image description here

The following is HTML page for this menu--

 <div id="wrapper1" class="container" ng-app="menuApp">
   <div id="nav1" ng-controller="menuController">
   <div><span> Dynamic Menu</span> </div>
         <ul>
            <li ng-repeat="menu in menus" class="has-children" ng-click="changeClass(menu)" lastOrFirst="{{menu.lastOrFirst}}" >
              <a href="{{menu.action}}">{{menu.title}} <span ></span></a>
              <ul ng-if="menu.menus">
              <div>
                <li ng-repeat="submenu in menu.menus" class="has-children">
                  <a href="{{submenu.action}}">{{submenu.title}}</a>
                      <ul ng-if="submenu.menus" ng-class="submenu.class">
                        <li ng-repeat="subsubmenu in submenu.menus">
                          <a href="{{subsubmenu.action}}">{{subsubmenu.title}}</a>
                        </li>
                      </ul>
                </li>
                </div>
              </ul>
            </li>
          </ul>
    </div>
</div>

CSS--

#wrapper1
    {
        width: auto;
        margin: 10px;
        text-align: left;
    }
    #nav1 div {color:Red; margin:10px;}
    #nav1 ul{list-style-type:none; padding:0; margin:0; }
    #nav1 ul li {display:inline-block; background-color:#E0E0E0; min-width:150px;}
    #nav1 ul li 
    {
        background-image:linear-gradient(to bottom, #ffffff, #eaeaea);
        background-repeat: repeat-x;
        border-bottom: 1px solid #d1d1d1;
        border-top: 1px solid #eaeaea;
        border-left: 1px solid #eaeaea;
        border-right: 1px solid #eaeaea;
            }
    #nav1 ul li:hover{background-color:#FFF; }
    #nav1 ul li:hover{ background-image:linear-gradient(to bottom, #eaeaea, #ffffff);
        background-repeat: repeat-x;
        border-bottom: 1px solid #eaeaea;
        border-top: 1px solid #d1d1d1;
        border-left: 1px solid #eaeaea;
        border-right: 1px solid #eaeaea;
        }
    #nav1 ul li:hover > a
     {
         border-bottom-color:#FFF;
         outline:0;
         text-decoration:none;
         border-top:solid 2px #1971c4;
         padding-top:12px;
         color:#1971c4;
         }
     #nav1 ul ul li:hover > a
     {
         border-top: 1px solid #eaeaea;
         }
     #nav1 ul li.has-children > a:after {
        content: "";
        background: url("http://www.cmegroup.com/etc/designs/cmegroup/cmegroupClientLibs/images/cme-header-sprite.png") no-repeat;
        width: 8px;
        height: 8px;
        display: inline-block;
        margin-left:5px;
    }
    #nav1 ul li a,visited{display:block; padding:15px; color:#888; text-decoration:none;}
    #nav1 ul li:hover > ul{display:block;}
    #nav1 ul li a:hover{color:#444;}
    #nav1 > ul li:hover a{color:#444;}

    #nav1 ul ul li{display:block;}
    #nav1 ul ul{position:absolute; background-color:#FFF; min-width:225px;}
    #nav1 ul ul li:hover{background-color:#F9F9F9;}
    #nav1 ul li:hover ul li a,visited{color:#888;}
    #nav1 ul ul li:hover ul{display:block;}
    #nav1 ul ul ul {margin: -47px 0 0 224px; background-color:#F9F9F9;}
    #nav1 ul ul ul li a:hover{color:#444;}
    #nav1 {vertical-align:middle; text-align:center;}

and Controller ----------------------------------JS---------------- menuApp.controller("menuController", function ($scope, $http) {

$scope.menus = [
{

    title: "Menu #1",
    action: "#"
},
{

    title: "Menu #2",
    action: "#",
    menus: [
      {
          title: "SubMenu #1",
          action: "#"
      },
      {
          title: "SubMenu #2",
          action: "#"
      },
      {
          title: "SubMenu #3",
          action: "#"
      },
      {
          title: "SubMenu #4",
          action: "#"
      }
    ]
},
{
    title: "Menu #3",
    action: "#",
    menus: [
    {
        title: "SubMenu #1",
        action: "#",
        menus: [
            {
                title: "Sub-SubMenu #1",
                action: "#"
            },
            {
                title: "Sub-SubMenu #2",
                action: "#"
            }
        ]
    }
  ]
},{
  title: "Menu #4",
  action: "#",
  menus: [
    {
        title: "SubMenu #1",
        action: "#",
        menus: [
            {
                title: "Sub-SubMenu #1",
                action: "#"
            },
            {
                title: "Sub-SubMenu #2",
                action: "#"
            }
        ]}]},{
  title: "Menu #5",
  action: "#",
  menus: [
  {
      title: "SubMenu #1",
      action: "#"
  },
  {
      title: "SubMenu #2",
      action: "#"
  }
]}];});

But I'm facing problem to show submenu area as highlighted in first image. I dont know how to get submenu's top left and top right.

Can anyone please help me out?

Thanks a lot in advance...

Ashok
  • 197
  • 3
  • 17

1 Answers1

1

I think you can do it through CSS, it should be posible if apply some styles to the submenu UL. Maybe the following could help you:

#nav1 ul ul ul {position: absolute; top: 40px; left: 0; width: 100%; background-color:#F9F9F9;}

It would be great if you could share your code running someplace.

Regards

Estefano
  • 26
  • 1
  • Thanks for your help, I added code in following location, please have a look at it. This is first time for me to add code in jsFiddle, and I was trying to resolve the issue as it is not working there. http://jsfiddle.net/ashokyede20/pLnvsnLa/15/ – Ashok Dec 02 '15 at 14:00
  • Ashok, you have to change and insert different CSS rules. Some colored backgrounds have been added in order to help to identify the different elements. You can see the updates here: http://jsfiddle.net/pLnvsnLa/31/ Maybe some updates needed when you insert more links in the different menu levels. – Estefano Dec 02 '15 at 15:36
  • Thanks Estefano, I have updated the code from the link that you provided http://jsfiddle.net/ashokyede20/pLnvsnLa/38/ Now you can see the UI in output window. Now the problem is like I want to see expanded submenu under Menu Tabs and its will start from First menu to Last manu(This is its width and start point.). Im not able to finalise its start point. – Ashok Dec 03 '15 at 05:51
  • Left should not be 0px. It should be the Left bottom of the "HOme" menu, and it should start from here for each and every submenu. – Ashok Dec 03 '15 at 05:57