2016-01-21 61 views
-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 

當我打電話給我的 「InterceptorFactory」 功能從」 ./factory-inteceptor.js',我的控制檯呈現出下一個錯誤:

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) 

回答

0

配置塊 - 在提供程序註冊和配置階段執行。只有提供者和常量可以注入到配置塊中。這是爲了防止服務在完全配置之前發生意外實例化。

這樣我不能在配置塊中注入工廠。該工廠將在配置塊添加到應用程序之前注入。

Angular documentation

0

確保factory-interceptor.js正在導出要註冊的工廠的功能。