-1

我有下一个配置(index.js)来调用我的拦截器工厂。

angular.module('pasApp')
 .factory('InterceptorFactory',['$q','$location',require('./factory-interceptor.js')])
 .config(['$stateProvider','$urlRouterProvider', '$httpProvider','InterceptorFactory',require('./config-app.js')])
 .run(['$ionicPlatform','$rootScope','$window','StorageFactory','$state','$timeout','$http',require('./run-app.js')]);

我的文件夹和文件顺序:

>config
  >config-app.js
  >factory-interceptor.js
  >index.js
  >run-app.js

当我从 './factory-inteceptor.js' 调用我的“InterceptorFactory”函数时,我的控制台出现下一个错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module pasApp due to:
Error: [$injector:unpr] Unknown provider: InterceptorFactory
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=InterceptorFactory
at http://localhost:8100/js/app.bundle.js:9874:12
at http://localhost:8100/js/app.bundle.js:14068:19
at getService (http://localhost:8100/js/app.bundle.js:14215:39)
at Object.invoke (http://localhost:8100/js/app.bundle.js:14247:13)
at runInvokeQueue (http://localhost:8100/js/app.bundle.js:14162:35)
at http://localhost:8100/js/app.bundle.js:14171:11
at forEach (http://localhost:8100/js/app.bundle.js:10142:20)
at loadModules (http://localhost:8100/js/app.bundle.js:14152:5)
at createInjector (http://localhost:8100/js/app.bundle.js:14078:11)
at doBootstrap (http://localhost:8100/js/app.bundle.js:11436:20)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=pasApp&p1=Error%3A%…otstrap%20(http%3A%2F%2Flocalhost%3A8100%2Fjs%2Fapp.bundle.js%3A11436%3A20)
4

2 回答 2

0

确保factory-interceptor.js正在为要注册的工厂导出功能。

于 2016-01-21T00:48:54.903 回答
0

配置块 - 在提供者注册和配置阶段执行。只有提供者和常量可以注入到配置块中。这是为了防止在完全配置之前意外实例化服务。

这样我就不能在配置块中注入工厂。该工厂将在配置块添加到应用程序之前注入。

角度文档

于 2016-05-19T22:24:56.290 回答