Domanda

I'm doing a redirect in the angularjs config and I can see the initial location there:

$routeProvider.otherwise({
     redirectTo: function(dummy, path, search) {
         return "/default-page";
     }
 });

The problem is how to pass this information anywhere else.

  • I can't inject a service in the config.
  • I can't inject the $rootScope either (so I can't broadcast it).
  • I can inject the $rootScopeProvider, but have to use its $get.
  • I can listen to $routeChangeSuccess but I can't see there the original location.
  • I can listen to $routeChangeStart, but it's no better.

What do I want it for: Unlock a feature by using a "magic" URL like

.../#/cheat/a/lot?answer=43

It's just a debugging hack, nothing security relevant.

I guess I should do it differently (a normal page calling $location?), but now I'm curious...

È stato utile?

Soluzione

Me stupid.

After having spend quite some time trying to figure it out and then writing the question....

Inject $rootScope and $location into the service and use it in

$rootScope.$on("$routeChangeStart", function() {...})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top