0

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.

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

6 Comments

Could you show me how you'd do it with inline array annotation please ?
services.factory('PoiService', ['$http', 'SETTINGS', require('./poiService')]). As said, there is a mismatch. Two items are expected to be injected, two items should be annotated in the same order. And the possible cause of this is that you don't see DI annotation and function signature simultaneously with coding style like that.
Is there any point of doing module.exports = poiService instead of module.exports = function($http, SETTINGS) { } ? Assuming the poiService file only contains the poiService definition and nothing else ? Thanks a lot by the way !
It is not necessary if inline array annotation is used. There is a reason to use named function if $inject annotation is used. Check also JP style guide for more details on the subject.
Is there any difference (performance, anything) in the way it's defined in controller 1 and 2 ? plnkr.co/edit/v2Kn7acOSTK3QYOOvPyt?p=catalogue @estus
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.