3

I'm trying to setup a controller that will redirect a user to a defined home page when they navigate to a specific url. This is so different users can all have their own landing page.

I have a state

.state('database.home', {
    url: '/home',
    templateUrl: "app/Database/Home/home.html",
    controller: "DatabaseHomeController"
})

and a controller

(function (ng, app) {

  "use strict";

  app.controller(
      "DatabaseHomeController",
      ["$rootScope", "$scope", "$state", "$stateParams", "sessionService", function ($rootScope, $scope, $state, $stateParams, sessionService) {

          console.log("Database home controller running");

          $stateParams.systemName = sessionService.auth.DefaultSystem;
          $stateParams.objectName = sessionService.auth.Homepage;

          if ($stateParams.objectName) {
              $state.transitionTo("database.object", $stateParams);
          } else {
              $state.transitionTo("login");
          }
      }]);
})
(angular, WebAppName);

This works once in Internet Explorer but on demand in Chrome/Firefox.

That line of logging is only shown the first time I click on the home link or type the url into IE. Every subsequent time I see

0x800a139e - JavaScript runtime error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

in angular.js

Edit:

Too clear up as two people now have asked. The $stateParams isn't the cause of the problem.

if (sessionService.auth.Homepage !== "") {
    $state.transitionTo("database.object", { objectName: sessionService.auth.Homepage, systemName: sessionService.auth.DefaultSystem });
} else {
    $state.transitionTo("login");
}

Behaves exactly the same in that it only works once on IE but every time in Firefox and Chrome.

Edit 2:

Changing $state.transistionTo for $state.go makes no difference the infinate loop on subsequent usages remains in IE.

Saurbaum
  • 415
  • 1
  • 4
  • 22
  • It probably has something to do with the assigning of variables to the `$stateParams` – devqon Jun 11 '15 at 09:26
  • If that were the case I would still expect the console.log to fire. – Saurbaum Jun 11 '15 at 09:29
  • Maybe this link will be of some use http://stackoverflow.com/questions/13853844/angular-js-ie-error-10-digest-iterations-reached-aborting – devqon Jun 11 '15 at 09:31
  • Thanks.There's some interesting parallels in that link and a lot of things I tried. None of them however cover typing the url in manually, when I discovered that was also causing the problem I ended up here. – Saurbaum Jun 11 '15 at 09:44
  • Why are you using stateParams for this? as I see there is no params in the url for 'database.home' route. `var systemName = sessionService.auth.DefaultSystem; var objectName = sessionService.auth.Homepage; $state.transitionTo("database.object", {'objectName' : objectName, 'systemName': 'systemName' });` – BotanMan Jun 22 '15 at 09:44
  • @BotanMan you are right it is unnecessary but it also don't solve the problem to change it. – Saurbaum Jun 22 '15 at 13:05
  • @Saurbaum what about using of $state.go (instead of transitionTo)? – BotanMan Jun 22 '15 at 13:27
  • @BotanMan $state.go does the same thing, in that is still fails on the digest loop. – Saurbaum Aug 28 '15 at 12:43
  • @Saurbaum, I think it's necessary to see your html structure and so on, from existing info everything is ok – BotanMan Aug 28 '15 at 15:34

1 Answers1

-1

A common trick with aplication runing under IE is that you must not put console.log.

So just comment out this line :

console.log("Database home controller running");
Marwen Cherif
  • 560
  • 5
  • 13
  • This doesn't sound right and if you have a source to state otherwise I would love to read it. Either way I checked by removing all the console logging and that makes no difference. – Saurbaum Jul 02 '15 at 15:23