我遵循John Papa的角度样式指南(https://github.com/johnpapa/angular-styleguide#routing)并在本指南中提供的角度ui路由器周围使用自定义封装。然而,包装不为我工作,并注入$状态时,我得到一个循环依赖错误:ui路由器封装中的Angular.js循环依赖错误
Uncaught Error: [$injector:cdep] Circular dependency found: $rootScope <- $timeout <- $$rAF <- $$animateQueue <- $animate <- toastr <- logger <- $exceptionHandler <- $rootScope <- $state <- routerHelper
我曾尝试手动进$状态使用$注射器但是这给了我一个未知的提供程序错误。
下面是代码:
(function() {
'use strict';
angular
.module('blocks.router')
.provider('routerHelper', routerHelperProvider);
routerHelperProvider.$inject = ['$locationProvider', '$stateProvider', '$urlRouterProvider', '$injector'];
function routerHelperProvider($locationProvider, $stateProvider, $urlRouterProvider) {
this.$get = RouterHelper;
$locationProvider.html5Mode(true);
RouterHelper.$inject = ['$state'];
function RouterHelper($state) {
var hasOtherwise = false;
var service = {
configureStates: configureStates,
getStates: getStates
};
return service;
function configureStates(states, otherwisePath) {
states.forEach(function (state) {
$stateProvider.state(state.state, state.config);
});
if (otherwisePath && !hasOtherwise) {
hasOtherwise = true;
$urlRouterProvider.otherwise(otherwisePath);
}
}
function getStates() {
return $state.get();
}
}
}
})();
尝试在HotTowel模板上使用angular-toastr时遇到同样的问题。使用$ inject延迟依赖关系为我工作。正如@Casey所说,不确定这是否是正确的方法。 – JenonD