0

I had this:

.controller('dashboardCtrl', function($scope, $timeout, $location, bionicoService, bionicoSamples, $state, $locale){

And everything worked fine, i could call my services for example bionicoSamples without a problem But i had to add a module for i18n and it requires this

.controller('dashboardCtrl', ['jlgI18nService', function( i18nService){

So when i added it to my code, my services stoped working, and i have no idea why, i'm king of new in angular and there is some conceptual stuff i don't understand well yet, for instance i really don't understand the difference betweem using "['module', function()" to "function('module')"

My code after trying to add the module is lilke this:

.controller('dashboardCtrl', ['jlgI18nService', function($scope, $timeout, $location, bionicoService, bionicoSamples, $state, $locale, i18nService){

I've also tried this, but is not working too

.controller('dashboardCtrl', ['jlgI18nService', '$scope', '$timeout', '$location', 'bionicoService',  '$state', '$locale', function($scope, $timeout, $location, bionicoService, bionicoSamples, $state, $locale, i18nService){

The error i'm getting is that my services are undefined, if i try to call bionicoSamples.function, it says that this ""function"" is not a function. I know the problem is in the way i'm importing the services and modules now with this i18n module, because before it was working fine

Thanks!

1
  • It sounds like a syntax error. Check your javascript console, an invaluable development tool. (In case Menu | Tools | Javascript console in case you're using chrome) Commented Jul 14, 2015 at 3:54

1 Answer 1

1

From the angular docs when using 'Inline Array Annotation' to declare your controller

When using this type of annotation, take care to keep the annotation array in sync with the parameters in the function declaration.

The order that you're injecting your services is wrong and you have more inputs to your function than injected services. Should be something like this:

.controller('dashboardCtrl', [
    '$scope',
    '$timeout',
    '$location',
    'bionicoService', 
    'bionicoSamples', // This is missing in yours
    '$state',
    '$locale',
    'jlgI18nService',
    function($scope, $timeout, $location, bionicoService, bionicoSamples, $state, $locale, i18nService){
Sign up to request clarification or add additional context in comments.

2 Comments

this is correct, it is necessary that the order of services in the array match exactly the order of the function parameters.
Also worth noting - Because the parameters are position-based when using the array syntax, the names in the function parameters don't have to match (whether this is good or bad is debatable)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.