首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >routeParams为空

routeParams为空
EN

Stack Overflow用户
提问于 2016-03-01 23:58:17
回答 1查看 184关注 0票数 2

我正在尝试使用$routeParams获取URL参数:

代码语言:javascript
复制
var myApp = angular.module('myApp', [
  'ngRoute',
  'appControllers',
  'appFilters',
  'appServices'
]).config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/admin/organisations/:organisation_id', {
    controller: 'UpdateOrganisationCtrl'
  });
}]);

在我的控制器中:

代码语言:javascript
复制
appControllers.controller('UpdateOrganisationCtrl', ['$rootScope', '$scope', '$http', '$window', '$routeParams',
function($rootScope, $scope, $http, $window, $routeParams) {

    console.log($routeParams.organisation_id);

}]);

但是,我以$routeParams的身份打印undefined is {},有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2016-03-02 00:15:06

您尝试访问的url应该是

localhost:3000/#/admin/organisations/56cde4bf911747ea200d5a63

ngRoute将使您的应用程序成为单页面应用程序,其中路由器的url的相关部分将位于#之后(漂亮地称为hashbang)。

Look at the example:

//给定:

// 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可能会起作用。

有关详细信息,请参阅这些链接:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35727531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档