Search code examples
angularjsangular-ui-routerstateangularjs-ng-include

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


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?


Solution

  • 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.