angular-ui-router错误:实例化TypeError:forEach不是函数

时间:2016-01-18 13:48:46

标签: angularjs angular-ui-router

我正在使用角度种子项目并尝试使用ui-router进行基于用户登录的路由。 我在控制台中收到以下错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module MyApp due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router.state due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router.router due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router.util due to:
TypeError: forEach is not a function
at new $UrlMatcherFactory
...

我在app.js中的代码是:

'use strict';

// Declare app level module which depends on views, and components
angular
    .module('MyApp', [
      'ui.router'
    ])
    .config(['$stateProvider', function($stateProvider) {
      $stateProvider
          .state("root", {
            url: "",
            template: "<section ui-view></section>",
            controller: function($state, user) {
              if ($state.is("root")) $state.go(user.loggedIn ? "main" : "login");
            }
          })
          .state("login", {
            templateUrl: "login/login.html",
            controller: "LoginCtrl"
          })
          .state("main", {
            templateUrl: "main/main.html",
            controller: "MainCtrl"
          });
    }])
    .controller("MainCtrl", function($scope, user, $state) {
      $scope.user = user;
      $scope.logout = function() {
        user.loggedIn = false;
        $state.go("root");
      }
    })
    .controller("LoginCtrl", function($scope, user, $state) {
      $scope.login = function() {
        user.loggedIn = true;
        $state.go("root");
      }
    });

我没有找到任何关于Google的内容,希望有人可以帮助我。 最好的问候

1 个答案:

答案 0 :(得分:0)

这可能是一个解决方案吗?

请参阅此链接:https://github.com/ded/script.js/issues/86