2016-01-18 31 views
0

我正在使用angular seed項目並嘗試使用ui-router進行基於用戶登錄的路由。 我在控制檯中以下錯誤:angular-ui-router錯誤:實例化TypeError:forEach不是函數

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"); 
     } 
    }); 

我沒有找到與谷歌任何東西,希望有人能幫助我在這裏。 致以問候

+0

你可以嘗試使用foreach嗎?全部小寫。 – Batuta

回答