我试图在JS中使用routeParams,但它总是以未定义的方式传入。
app.controller('ShowKey', function($scope, $http, $routeParams, $log) {
$log.info('SomeCtrl - starting up, yeah!');
$log.info($routeParams);
$scope.getKey = function() {
$log.info($routeParams);
};
});除了用app.controller调用routeParams之外,还有什么需要设置的吗?
发布于 2014-06-12 18:10:47
1-你考虑过配置中的任何routeParams吗? 2-如果你想在你的配置中得到你的routeParams,你不能
-你必须使用:
相反,$route.current.params
app.config(function($routeProvider){
$routeProvider.when('/path/:yourRouteParam'
templateUrl:"your template url address",
controller:'your controller',
resolve: {
resolbeObject: function($route){
//**here you cannot use $routeParam to get "yourRouteParam"** property
// you must use : $route.current.params
}
}
})
});但是在您的控制器中,您可以使用yourRouteParam获得$route.params,只要您已经在您的路由中定义了路由params,请如下所示:
$routeProvider.when('/path/:**yourRouteParam**备注如果您想要定义任何必须使用(:),而不是(?)的路由参数
https://stackoverflow.com/questions/24190737
复制相似问题