htmlangularjsangularjs-ng-include

AngularJS Load html files after log in


Good afternoon everybody,

I have an index.html file that contains all the application views : enter image description here

I'm trying to know if is it possible to load all the ng-include after user log in and not before ?

My first idea was to replace index.html content by login.html content and then redirect to another html file (Home.html which contains the index.html content) once user is logged but it doesn't work and I think it's not the way AngularJs works on.

I tried to add , it works well when it's first connection but when user sign out and reconnect it doesn't work anymore specially when we want to redirect the user on the same page where he was before sign out because I think AngularJs must reevaluate the logic.

If you have any ideas or advises I would appreciate.

Thank you,


Solution

  • If you set the property isAuthenticated on the $scope, (or on the $rootScope if you want this property to be inherited by all scopes) when the user is logged in, then you could use the NgIf directive to solve this

    <div class="table" ng-if="isAuthenticated" ng-show="location=='nodes'" ng-include="'views/nodes/nodes.view.html'"></div>