javascript - Angularjs $on $routeChangeSuccess error on first load -


I have used the Internet for the past few days while trying to figure out how to fix this problem. Not that if I am not answering just questions or it is a simple solution that I can not see.

My issue is that in my $ root provider, I have a property to determine whether a user has to log in or to view a page using a variable called 'isfree' In order to determine what is set to the right or wrong, it is called 'reach' in each way.

Example:

$ routeProvider. When ('/', {Controller: 'Home Controller', Template Answer: 'Partial / Home', Access: {isFree: true}});

Then I have one. There is a block of code in the array function, which looks for route changes and checks if the page needs to enter the user and if they are already signed in. If the page 'isFree' is set to True then it should load the page, otherwise it checks to see whether the user is signed or not, and if he does not redirect back home.

  ('$ RootScope', '$ location', function ($ root, $ location) {$ root. $ ('$ RouteChangeSuccess', function (scope, curr, prewerout) {If (! CurRoute.access.isFree & amp; amp; amp; amp; loggedIn) {$ location.path ('/');}});  

The problem is that this code is not working. The problem is that when you first load on the home page (which is set to isFree right) the console returns an error that is not defined 'isFree'. The homepage is loading and the site works properly with that first error. I want to pop the error in the first place. As far as I can understand that when I first link to the homepage, it tries to check the free property for free for the first time before the free load, but I have not solved my problem yet. If someone knows what I can do to fix this small problem, it will be appreciated.

Looks like your curroute .access is not defined, so try instead as your statement Do:

  if ((CurRoute.access ||! CurRoute.access.isFree) & amp; login) {$ location.path ('/'); }  

Comments