角JS路线造成死循环 [英] Angular JS route causing infinite loop
本文介绍了角JS路线造成死循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出为什么点击后页面没有定位到它的模板。该网址更新,我也没有JS错误。我相信它的加载的文件,但随后无限加载控制器。我发现了这一点,我把一个的console.log后('试!')
在我SessionsController的实例。
布局
< DIV NG-视图>< / DIV>
我的视图
< A HREF =/测试>我严肃&LT的链接; / A>
我的JS
window.MainController =功能($范围,$路径,$ routeParams,$位置){
。$ $范围路径= $路线;
。$ $范围位置= $位置;
$ $范围= routeParams $ routeParams。
的console.log($路线);
的console.log($位置);
的console.log($ routeParams);
};。MainController $注射=$范围,$路线];window.app = angular.module('web_client',[],功能($ routeProvider,$ locationProvider){
返回$ routeProvider.when('/测试',{
templateUrl:/partials/other_stuff/index.html',
控制器:'myController的
});
});
window.MyController =功能($范围,$ HTTP){
的console.log('无限循环!');
};
而在的谐音/会话/ new.html
,我有一双大而明亮的:
FOOBAR!
解决方案
我唯一看到的是缺少括号和遗漏逗号。你可以用这个试试:
$ routeProvider
。当(/登录,{
templateUrl:会话/ new.html
控制器:SessionsController
})
。除此以外({
redirectTo:/
});
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!
解决方案
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: "/"
});
这篇关于角JS路线造成死循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文