Tony
Tony

Reputation: 12695

AngularJS - $timeout is not a function

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) {
...
}]);

Upvotes: 5

Views: 21642

Answers (2)

Rasalom
Rasalom

Reputation: 3111

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

Upvotes: 19

kubuntu
kubuntu

Reputation: 2535

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) {
...
}]);

Upvotes: 3

Related Questions