Facu Ferrari Facu Ferrari - 8 months ago 21
Javascript Question

ng-hide based on parent state

I've got a navbar in my main controller and I want a link to show/hide based on the url. I'm using ui-router for routing so I've thought I could use $state for getting the parent state of the current state but I don't know how. I've done this before to get the current state and it works

<li ng-hide="$state.current.name === 'new-sector'">
<a ui-sref="new-sector">+ Add new sector!</a>

But now, I'm working with nested states so the current state is new-sector.location.
My problem is that I want that link to hide in all new-sector child states!

Thanks in advance for help!


You can always use $state.includes(stateName) to check if the current active state is equal to or is the child of the state stateName.

Here is an example plnkr that shows the usage of $state.includes.

More details on the wiki