Trip Trip - 3 months ago 32
AngularJS Question

Angular JS route causing infinite loop

I'm trying to figure out why the page doesn't navigate to its template when clicked. The URL updates, and I have no JS errors.. I believe it loads the file, but then it infinitely loads the controller. I found this out after I put a

console.log('test!')
in my SessionsController's instantiation.

The layout

<div ng-view></div>


My View

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


My 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!');
};


And in
partials/sessions/new.html
, I have big and bright :

FOOBAR!

Answer

The only thing I see are missing brackets and a missing comma. You may try with this:

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