这似乎是一个愚蠢的问题,但我浏览了全世界的互联网,但找不到答案。
我在我的应用程序中配置了一条路由,因此:
$routeProvider.when(
"/customer/:customerId", {
templateUrl: "/angular/components/booking-system/customers/templates/customer-template.html",
controller: "customersCtrl"
}
)
但我不知道在 customer-template.html 中哪里提取 customerId 参数。有人能解释一下吗?如何访问代码中的参数?
我正在使用以下方式导航到此路线:
$scope.customerDetails = function(customerId) {
$location.url("/customer/" + customerId);
}
这是最好的导航方式吗?
最佳答案
您可以在 Controller 中访问它,如下所示:
.controller('customersCtrl', ['$scope', '$routeParams', function($scope,
$routeParams){
$scope.customerId = $routeParams.customerId; //Make use of routeParams
}])
关于javascript - 在 Angular 中提取路由配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30074157/