如果我有一个始终作为查询字符串传递的特定路由参数,那么使用 Angular 的$routeParams
服务检索参数和使用它的$location.$$search
服务有区别吗?如果是这样,一个比另一个更可取吗?
网址://localhost:80/app/profile?id=42
$routeParams
方法:
app.controller('ProfileController', ['$routeParams', function($routeParams) {
console.log($routeParams.id);
}]);
$location
方法:
app.controller('ProfileController', ['$location', function($location) {
console.log($location.$$search.id);
}]);
我已经$location
在需要执行问题中详述的行为的控制器中作为依赖注入。此外,控制器的模块还没有依赖于ngRoute
.