javascript - 在服务中使用服务 Angularjs

标签 javascript angularjs twitter-bootstrap angular-ui angular-ui-bootstrap

我正在尝试将 bootstrap-ui $modal 服务注入(inject)到我的工厂中,但是当我这样做时,我会遇到循环依赖问题,而当我不这样做时, $modal 未定义。代码如下:

retryModule = angular.module('g4plus.retry-call', ['ui.bootstrap'])

retryModule.factory 'RetryCall', ($q, $rootScope)->
  requests = {}
  failedRequests = {}
  uniqueId = 0
  modalInstance = undefined
  modalClose = true

### Some more code

    alertUser = ()->
    modalInstance = $modal.open
      template: """
        <div class="modal-dialog">
          ... Some more code ...

如何在我的工厂中使用 $modal?请不要要求我将此代码放入指令中,因为这违背了目的。如果我可以将其放入指令中,我早就完成了这个项目。 Controller 也是如此。

谢谢!

如果我将 $modal 注入(inject)我的工厂,循环依赖错误是:

未捕获错误:[$injector:cdep] 发现循环依赖:$modal <- RetryCall <- $http <- $compile

最佳答案

接受的答案没有提供有效的解决方案。

这里的问题是 $modal 依赖于 $http$modal 无法在拦截器中请求 $http,因为 $http 尚不存在(因为您仍处于配置阶段,配置$httpProvider)。

用户 thaumant 的回答解释了如何解决此问题:

I need two instances of AngularJS $http service or what?

关于javascript - 在服务中使用服务 Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22159834/

相关文章:

html - 100% 宽度的 Twitter Bootstrap 3 模板

html - 摆脱导航栏上方的分割隔线,Bootstrap3

javascript - 存储来自不同 Intent 的多个参数

javascript - Angular-JWT 授权 header 异常

javascript - 绑定(bind) ng-options 数组的一个属性

angularjs - 在 AngularJS 中将货币从美国转换为英国

html - 元素之间的边距

javascript - 扩展和收缩元素

javascript - if , else if - javascript 函数只工作一次

javascript - 使用函数数据动态加载onclick函数