$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 來解析參數。

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM