我正在尝试使用 Angular 的 RouteParams 从我的 url 获取查询值。
我在我的 html 页面中包含了 Angular-route:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.min.js"></script>
在我的应用程序中包含 Ng-Route:
var app = angular.module('app', [
'ngRoute',
'reportController'
]);
并按如下方式设置我的 Controller :
var reportController = angular.module('reportController', []);
reportController.controller('CandidateCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
console.log(JSON.stringify($routeParams, null, 4));
$scope.person = $routeParams.person;
}]);
但是,当我访问以下 URL 时,routeParams 是一个空对象:{}。
http://localhost:8080/report?person=afe75cc7-fa61-41b3-871d-119691cbe5ad
我做错了什么?
编辑:
我已经配置了可能的路线 - 我的routeParams对象仍然为空。我试过:
famaApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/report:person', {templateUrl: 'Report.html', controller: 'CandidateCtrl'});
}]);
和
when('/report?person', {templateUrl: 'Report.html', controller: 'CandidateCtrl'});
最佳答案
而不是像这样访问 http://localhost:8080/report?person=afe75cc7-fa61-41b3-871d-119691cbe5ad
尝试像这样访问它 http://localhost:8080/#/report/afe75cc7-fa61-41b3-871d-119691cbe5ad
您将在$route.Params
中获得guid
关于javascript - Angular $routeParams 空对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32506316/