【发布时间】:2016-02-19 23:35:15
【问题描述】:
在某些情况下,我想导航到默认或“否则”状态。所以我需要从控制器获取路由对象中配置的其他状态。
当我尝试在指令的控制器中注入 $urlRouterProvider 时,出现错误:
错误:[$injector:unpr] 未知提供者:$stateProviderProvider
我做错了什么?
示例代码:
.config([ '$stateProvider', '$urlRouterProvider', '$locationProvider', ( $stateProvider, $urlRouterProvider, $locationProvider ) => {
$locationProvider.html5Mode(true);
$urlRouterProvider.otherwise('/bbv/voorstellen/open');
(...routing code)
}])
指令:
.directive('bbvNav', [ '$state', ( $state ) => {
return {
restrict: 'E',
template,
scope: {
titleBind: '&',
onButtonClick: '&'
},
bindToController: true,
controller: [ '$scope', function ( $scope ) {
$state.go( <NAVIGATE TO URLROUTERPOVIDER.OTHERWISE> );
console.log('Accessing $urlRouterProvider.otherwise state:'); // How do I get the value of $urlRouterProvider.otherwise here?
}
}
})
【问题讨论】:
-
你能给我们代码示例吗?没有您的代码,要猜测发生了什么要困难得多。
标签: angularjs angular-ui-router