本文介绍了1.1.5角路线Html5Mode调用堆栈大小Exceede的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Word preSS作为我的一处骨干前来角项目,我是新来的角,花费了大量的时间阅读和学习。

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.

我在这一点上的问题是,我设法让路由的工作,但由于某些原因的默认方式(不HTML5模式)无法工作。

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.

我有一个列表,点击链接时,我应该去一个参数化的URL,我得到这个错误

I have a list, when clicking on a link I should go to a parametrized url and I get this error

我有一个应用程序,服务和控制器的文件,我将在这里发布的内容:

I have an app, services and controller files, I will post the contents here:

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>

在模板。角路由器是相对于当前的URL。

In the template. Angular router are relative to the current URL.

这篇关于1.1.5角路线Html5Mode调用堆栈大小Exceede的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:47