0

I have an AngularJS web app. When a user gets to my domain root URL root-domain/ my app checks automatically his navigator language and if different than english it should automatically include the language in the url, like root-domain/es. This makes my controller reloads and I would like to avoid this for performance and user experience purposes.

I have read the solution provided Can you change a path without reloading the controller in AngularJS? by @Vigrond but for some reason I get next error:

TypeError: $rootScope.$on is not a function
    at LocationUrl.$location.path (app.js:140)
    at Constructor.HomeCtrl (home.js:15)

in line: var un = $rootScope.$on('$locationChangeSuccess', function () {

According to the approach, you don´t have to do anything else, but I guess I´m missing something.

Rober
  • 5,868
  • 17
  • 58
  • 110
  • First, you can just have some checks, so your controller will init only once and 2nd time init will be just empty. Second, this error means that most probably you have problems with minification/param order -- but one unlikely tells you more without code/plunk. Third, if you use latest ui-router there are dynamic params for this case. – Petr Averyanov May 28 '19 at 11:59
  • I will try to develop a plunker, but it won´t be easy to reproduce. The code is failing in development environment which is not minified. – Rober May 28 '19 at 13:42

0 Answers0