由於John Papa - 10 AngularJS Patterns presentation建議我嘗試實現額外功能,異常處理:
exceptionHandlerDecorator.$inject = ['$provide'];
function exceptionHandlerDecorator($provide){
$provide.decorator('$exceptionHandler', handleException);
}
handleException.$inject = ['$delegate', 'ExceptionHandlerService'];
function handleException($delegate, ExceptionHandlerService){
function handle(exception, cause){
$delegate(exception, cause);
ExceptionHandlerService.handle(exception.message);
}
return handle;
}
ExceptionHandlerService.$inject = ['$modal'];
function ExceptionHandlerService($modal){
//do things
}
但是當我嘗試TI從角UI注入$modal
到ExceptionHandlerService
Bootstrap我得到了Error: $injector:cdep Circular Dependency,這讓我感到害怕。我試圖用接受的解決方案,從非常類似的問題,Injecting $http into angular factory($exceptionHandler) results in a Circular dependency:
function ExceptionHandlerService($window, $injector){
var $modal = $injector.get('$modal')
}
但它給了我完全相同的結果 - Error: $injector:cdep Circular Dependency
。有沒有人有類似的問題,並知道解決方案?提前感謝您的關注。
當你嘗試解決方案時,你是否刪除了行'ExceptionHandlerService。$ inject = ['$ modal'];'? – Ian
@Ian是的,我刪除了這一行 –