[英]Angular 1.1.5 Route Html5Mode Call Stack Size Exceede
I am using Wordpress as a backbone in one of my many to come angular projects, I'm new to angular, spend a lot of time reading and learning. 我正在将Wordpress用作众多即将到来的角度项目中的一个骨干,我是角度不熟悉的新人,花了大量时间阅读和学习。
My problem at this point is that I managed to make routing work, but for some reason the default way (without html5 mode) isn't working. 我现在的问题是我设法使路由工作,但是由于某种原因,默认方式(没有html5模式)不起作用。
I have a list, when clicking on a link I should go to a parametrized url and I get this error 我有一个列表,单击链接时,我应该转到参数化的URL,但出现此错误
http://screencast.com/t/024t0Pl6 http://screencast.com/t/024t0Pl6
I have an app, services and controller files, I will post the contents here: 我有一个应用程序,服务和控制器文件,我将在这里发布内容:
app.js app.js
angular.module('AngularWP', ['controllers', 'services', 'directives'])
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
controller: 'ListController',
templateUrl: 'templates/list.html'
})
.when('/view/:id', {
controller: 'DetailController',
templateUrl: 'templates/detail.html'
})
.otherwise({
redirectTo: '/'
});
}
]);
services.js services.js
angular.module('services', [])
.factory('getAllPosts', ['$http',
function($http) {
return {
get: function(callback) {
$http.get('/wordpress/api/get_recent_posts/').success(function(data) {
// prepare data here
callback(data);
});
}
};
}
])
controller.js controller.js
angular.module('controllers', [])
.controller('ListController', ['$scope', 'getAllPosts',
function($scope, getAllPosts) {
getAllPosts.get(function(data) {
$scope.posts = data.posts;
});
}
])
.controller('DetailController', ['$scope', 'getAllPosts', '$routeParams',
function($scope, getAllPosts, $routeParams) {
getAllPosts.get(function(data) {
console.log(data);
for (var i = data.count - 1; i >= 0; i--) {
//data.count[i]
//console.log('post id is ' + data.posts[i].id);
//console.log('routeparam is ' + $routeParams);
if (data.posts[i].id == [$routeParams.id]) {
//console.log(data.posts[i]);
$scope.post = data.posts[i];
}
};
});
//$scope.orderProp = 'author';
}
]);
What could be the problem? 可能是什么问题呢?
Apparently the solution to this problem was this: 显然,此问题的解决方案是:
<script>
document.write('<base href="' + document.location + '" />');
</script>
In the template. 在模板中。 Angular router are relative to the current URL.
角路由器是相对于当前URL的。
I had the same issue. 我遇到过同样的问题。 The issue was solved for me by switching to 1.0.7.
通过切换到1.0.7为我解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.