3103
3103

Reputation: 69

angularjs Error: [$injector:strictdi] function($httpProvider) is not using explicit annotation and cannot be invoked in strict mode

angular.module('app',[])
.factory('httpRequestInterceptor','APP_VERSION', function (APP_VERSION) {
    var DNAME = sessionStorage.getItem('DNAME');
    var DID = localStorage.getItem('uid');
    return {
      request: function (config) {      
        config.headers['Browser-Agent'] = 'Abc/'+DNAME+'/'+DID+'/'+APP_VERSION+'';
        return config;
      }
    };
})
.config(function($httpProvider) {
    $httpProvider.interceptors.push('httpRequestInterceptor');
});

Im gettig the below error.

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:strictdi] function($httpProvider) is not using explicit annotation and cannot be invoked in strict mode

Upvotes: 1

Views: 388

Answers (2)

georgeawg
georgeawg

Reputation: 48968

The factory is missing square brackets:

angular.module('app',[])
̶.̶f̶a̶c̶t̶o̶r̶y̶(̶'̶h̶t̶t̶p̶R̶e̶q̶u̶e̶s̶t̶I̶n̶t̶e̶r̶c̶e̶p̶t̶o̶r̶'̶,̶ ̶'̶A̶P̶P̶_̶V̶E̶R̶S̶I̶O̶N̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶ ̶(̶A̶P̶P̶_̶V̶E̶R̶S̶I̶O̶N̶)̶ ̶{̶ 
.factory('httpRequestInterceptor',['APP_VERSION', function (APP_VERSION) {
    var DNAME = sessionStorage.getItem('DNAME');
    var DID = localStorage.getItem('uid');
    return {
      request: function (config) {

        config.headers['Browser-Agent'] = 'Abc/'+DNAME+'/'+DID+'/'+APP_VERSION+'';
        return config;
      }
    };
̶}̶)̶
}])

And the .config is missing explicit annotation:

̶.̶c̶o̶n̶f̶i̶g̶(̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶h̶t̶t̶p̶P̶r̶o̶v̶i̶d̶e̶r̶)̶ ̶{̶
.config(["$httpProvider", function($httpProvider) {
    $httpProvider.interceptors.push('httpRequestInterceptor');
̶}̶)̶
}]);

For more information, see

Upvotes: 0

Merlin
Merlin

Reputation: 4927

Remove APP_VERSION parameter after httpRequestInterceptor and it should work.

angular.module('app',[])
.factory('httpRequestInterceptor', function (APP_VERSION) {

Upvotes: 0

Related Questions