我正在尝试使用$routeParams获取URL参数:
var myApp = angular.module('myApp', [
'ngRoute',
'appControllers',
'appFilters',
'appServices'
]).config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/admin/organisations/:organisation_id', {
controller: 'UpdateOrganisationCtrl'
});
}]);在我的控制器中:
appControllers.controller('UpdateOrganisationCtrl', ['$rootScope', '$scope', '$http', '$window', '$routeParams',
function($rootScope, $scope, $http, $window, $routeParams) {
console.log($routeParams.organisation_id);
}]);但是,我以$routeParams的身份打印undefined is {},有什么想法吗?
发布于 2016-03-02 00:15:06
您尝试访问的url应该是
localhost:3000/#/admin/organisations/56cde4bf911747ea200d5a63
ngRoute将使您的应用程序成为单页面应用程序,其中路由器的url的相关部分将位于#之后(漂亮地称为hashbang)。
//给定:
// URL:http://server.com/index.html#/Chapter/1/Section/2?search=moby
// Route: /Chapter/:chapterId/Section/:sectionId
//
//然后
$routeParams ==> {章节2‘:’1‘,章节2’:‘2’,搜索:‘moby’}
但是,如果您为angular的$location服务使用HTML5Mode,那么您提供的url可能会起作用。
有关详细信息,请参阅这些链接:
https://stackoverflow.com/questions/35727531
复制相似问题