javascript - 在 Angular 中提取路由配置

标签 javascript angularjs

这似乎是一个愚蠢的问题,但我浏览了全世界的互联网,但找不到答案。

我在我的应用程序中配置了一条路由,因此:

$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/

相关文章:

javascript - 处理 URL 方案 react-native 和 Swift

javascript - Fancytree:添加分页

node.js - 从azure网站上的子文件夹托管的nodejs应用程序

javascript - 使用 angularjs routeprovider 进行护照 facebook 身份验证

javascript - ES6 : this is undefined despite using bind()

javascript - 将属性从父级复制到 Angular Directive(指令)中的内部控件

javascript - Python从<script> html标签内获取数据值

javascript - 如何将控件放入 HTML5 Canvas 绘图中?

javascript - jshint 无法识别 devel

javascript - 在 KendoUI 的模板中使用时,不会调用 AngularJS ng-click