5

I try to inject $timeout in the run function but I get that it is not a function when I try to call it. Why ?

var mainApp = angular.module('mainApp', ['ngRoute', 'ngAnimate', 'ui.bootstrap', ngCookies']);

mainApp.run(['$rootScope', '$location', '$timeout'
        function ($rootScope, $location, $route, authService, $timeout) {
...
}]);
1
  • 1
    there is lot of syntax error in this code. correct it and try again Commented Dec 3, 2014 at 12:59

2 Answers 2

19
mainApp.run(['$rootScope', '$location', '$timeout'
        function ($rootScope, $location, $route, authService, $timeout) {
...
}]);

should be:

mainApp.run(['$rootScope', '$location', '$route', 'authService', '$timeout',
        function ($rootScope, $location, $route, authService, $timeout) {
...
}]);

see 'The array annotation' part here:

https://docs.angularjs.org/api/auto/service/$injector

Sign up to request clarification or add additional context in comments.

Comments

3

When you annotate function with names of dependencies, the order of appearance should match.

...
mainApp.run(['$rootScope', '$location', '$route', '$timeout', 'authService', 
        function ($rootScope, $location, $route, $timeout, authService) {
...
}]);

Comments

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.