我试图在我的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);
};
});
除了使用routeParams调用app.controller之外,我还需要设置什么吗?
最佳答案
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
}
}
})
});
但是在你的 Controller 中,你可以使用 $route.params 获取你的RouteParam,只要你在路由配置中定义了路由参数,如下所示:
$routeProvider.when('/path/:**yourRouteParam**
注意如果你想定义任何路由参数,你必须使用(:),而不是(?)
关于javascript - Angular 路线参数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24190737/