what is the purpose of $state.includes in angularjs?

ajai picture ajai · Apr 20, 2017 · Viewed 10.4k times · Source

I'm new in angularjs, I've little confuse between ng-include and $state.includes. Can anyone please suggest me why we using the $state.includes instead of ng-include directive?

Answer

Vahid Najafi picture Vahid Najafi · Apr 20, 2017

Imagine you have a parent menu with some child menus. For each child menu you have something like this for adding active class:

ui-sref-active="active"

But you also need to add active class for parent menu when you navigate to each of the child states.Then you can use ui-router includes.

<li ng-class="{ active: state.includes('parentState') }">

Note: You must add this to your controller:

$scope.state = $state;

About ng-include, it doesn't relate to $state.include. It compiles external html into the directive.