I have the following code:
function configRestangular(RestangularProvider, BASE_URL) {
RestangularProvider.setBaseUrl(BASE_URL);
RestangularProvider.setDefaultHeaders({ 'Content-Type': 'application/json' });
RestangularProvider.setErrorInterceptor(
function (response, deferred) {
if (response.status === 401 || response.status === 403) {
//$state.go('login');
}
});
}
core.config(configRestangular);
When I pass $localStorage
to function configRestangular(RestangularProvider, BASE_URL)
, application throws an exception.
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module app.core due to: Error: [$injector:unpr] Unknown provider: $localStorage http://errors.angularjs.org/1.4.0-rc.2/ $injector/unpr?p0=%24localStorage
I have registered the ngStorage
module in main module. ngStorage.js
file is also added in my main page. $localStorage
service is working in all controllers except this config function.
I am using https://github.com/gsklee/ngStorage module for localStorage.
您还必须添加'ngStorage'
和'RestangularProvider'
作为应用程序的依赖项:
var app = angular.module('MyApp', ['ngStorage','RestangularProvider']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.