adaba
adaba

Reputation: 384

Angular : Can't access injected dependency constant

I'm using Webpack 1.13.2 with Angular 1.5.8 and I can't manage to access my "SETTINGS" constant from my poiService file.

TypeError: Cannot read property 'API_URL' of undefined

http://plnkr.co/edit/6repllAk39kv4Enfw8RU?p=catalogue

Thanks for help.

Upvotes: 0

Views: 96

Answers (1)

Estus Flask
Estus Flask

Reputation: 222354

PoiService has mismatching annotation:

services.factory('PoiService', ['SETTINGS', require('./poiService')])

service definition and

module.exports = function ($http, SETTINGS) { ... }

function signature.

For this reason it may be not advisable to keep factory function and service definition in separate files. And even if there's a need to do this, it is preferable to use named function and $inject annotation instead of inline array annotation:

services.factory('PoiService', require('./poiService'))

...

poiService.$inject = ['$http', 'SETTINGS'];
function poiService($http, SETTINGS) { ... }
module.exports = poiService;

Upvotes: 1

Related Questions