1

I'm trying to make selected link on navigation bar highlighted based on current location in the url. For that I have written following function in controller for navbar:

$scope.isActive = function(route) {
  return route === $location.path();
};

and in html I have this:

<li ng-class="{active: isActive('/admin')}"><a href="/admin">Admin</a></li>

This works well for simple url but does not perform well for urls with id and subpaths. I mean if I have url as 'item/:id' it does not match in isActive function and does not get highlighted, also I want to highlight same li for multiple sub routes like item menu should be highlighted for items & items/:id & items/my. Any idea how can I achieve this?

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • Just wanted to give you a hint, how the "standard" UI-Router soltuion was designed... ;) Because as far as I remeber (from my plays...) it could be applied on LI as well, just ui-sref must be in place... – Radim Köhler Nov 28 '14 at 05:52
  • @RadimKöhler ok, I updated some bits here and there and now its working somewhat. Only problem is I can not directly go to abstract state. I mean I have given abstract state id into ui-sref so its getting highlighted everytime a child state is selected but when I click on that link it gives error like `Cannot transition to abstract state 'item'` – Harry Joy Nov 28 '14 at 06:06
  • Yes yes... but that is not an issue! Why? just remove the abstract... and try to create some handling arround... to select one substate as default. Check it here http://stackoverflow.com/q/23658846/1679310 and in case you are using 0.2.13 - http://stackoverflow.com/q/27120308/1679310 – Radim Köhler Nov 28 '14 at 06:07