ui-router $ stateParams与$ state.params
使用ui-router,可以将$state或$stateParams注入控制器中,以访问URL中的参数。但是,$stateParams仅通过访问参数会公开属于访问它的控制器管理的状态的参数及其父状态,而$state.params具有所有参数,包括处于任何子状态的参数。 给定以下代码,如果我们直接加载URL http://path/1/paramA/paramB,则这是控制器加载时的样子: $stateProvider.state('a', { url: 'path/:id/:anotherParam/', controller: 'ACtrl', }); $stateProvider.state('a.b', { url: '/:yetAnotherParam', controller: 'ABCtrl', }); module.controller('ACtrl', function($stateParams, $state) { $state.params; // has id, anotherParam, and yetAnotherParam $stateParams; // has id and anotherParam } module.controller('ABCtrl', function($stateParams, $state) { $state.params; // has id, anotherParam, and yetAnotherParam $stateParams; // has id, …