Adeel Khan Adeel Khan - 21 days ago 6
AngularJS Question

navigation does not work with ng-if condtion

hi i need help from you guys, when i add in ul with ng-if condition navigation does not work, how to solve this please help

<nav id="menu" class="nav-main" role="navigation">
<ul class="nav nav-main" ng-if=" $ctrl.getCurrentUser().user_type == 'Customer'">
<li class="">
<a href="/dashboard">
<i class="fa fa-home" aria-hidden="true"></i>
<span>Dashboard</span>
</a>
</li>
<li class="nav-parent">
<a href="#">
<i class="fa fa-table" aria-hidden="true"></i>
<span>Jobs</span>
</a>
<ul class="nav nav-children">
<li><a href="/addjob">Add New Job</a></li>
</ul>
</li>

<ul class="nav nav-main" ng-if=" $ctrl.getCurrentUser().user_type == 'Customer'">

Answer

I had same problem, below solution worked for me.

Define in your controller

$scope.user = $this->getCurrentUser();

And use ng-show instant of ng-if

<ul class="nav nav-main" ng-show=" user.user_type == 'Customer'">

Please try this if it works for you.