$routeParams 实现路由指定参数

【摘要】后台管理系统权限控制到按钮级别,将每一个资源的key绑定在url中,渲染页面的时候去根据key来获取当前页面的按钮列表。

router.js

angular.module("app.router", [])
  .config(['$routeProvider',function($routeProvider) {
    $routeProvider
      //单个参数
      .when("/index/:paramName",{              
        templateUrl: "app/index",
        controller: "indexCtrl"
      })
      //多个参数  
      .when("/index/:paramName1/:paramName2",{               
        templateUrl: "app/index",         
        controller: "indexCtrl"       
      })
  }])
 }());

controller.js

;(function () {
  "use strict";
  angular.module("app.ctrls")
  .controller('indexCtrl', ['$scope', 'indexServices', '$routeParams',
  function ($scope, indexServices, $routeParams) {
    $routeParams.paramName
}]); }());

  

通过  :paramName 来指定路由的参数,然后在页面的控制器中使用 $routeParams.paramName 来解析参数。

  

 

原文地址:https://www.cnblogs.com/koto/p/7305662.html