小编典典

Angular JS路由导致无限循环

angularjs

我试图弄清楚为什么页面在单击时没有导航到其模板。URL更新,并且我没有JS错误。。我相信它 会加载
文件,但随后会无限加载控制器。我console.log('test!')在SessionsController的实例化中添加了代码后,发现了这一点。

布局

<div ng-view></div>

我的看法

<a href="/testing"> My link of seriousness </a>

我的JS

window.MainController = function($scope, $route, $routeParams, $location) {
  $scope.$route = $route;
  $scope.$location = $location;
  $scope.$routeParams = $routeParams;
  console.log($route);
  console.log($location);
  console.log($routeParams);
};

MainController.$inject = ["$scope", "$route"];

window.app = angular.module('web_client', [], function($routeProvider, $locationProvider) {
  return $routeProvider.when('/testing', {
    templateUrl: '/partials/other_stuff/index.html',
    controller: 'MyController'
  });
});


window.MyController = function($scope, $http) {
  console.log('Infinite Loop!');
};

在里面partials/sessions/new.html,我有个大而光明的人:

FOOBAR!

阅读 290

收藏
2020-07-04

共1个答案

小编典典

我唯一看到的是缺少括号和逗号。您可以尝试以下方法:

$routeProvider
  .when("/login", {
    templateUrl: "sessions/new.html",
    controller: SessionsController
  })
  .otherwise({
    redirectTo: "/"
  });
2020-07-04