$timeout not defined error in AngularJS app

前端 未结 1 883
不思量自难忘°
不思量自难忘° 2020-12-16 09:20

I have the following code:

app.factory(\'Position\', [\'$timeout\', function() {

    var position = {
        latitude: 44,
        longitude: 26
    };

           


        
相关标签:
1条回答
  • 2020-12-16 09:52

    You did not inject $timeout. It should be as follows.

    app.factory('Position', ['$timeout', function($timeout) {
        ...
    }]);
    

    Declaration this way ensures that services are correctly identified when your JavaScript code gets minified. For further information on how this helps minification, see A Note on Minification and Declaring AngularJS Modules For Minification

    If minification is not in your plans (e.g for quick test), you can simply go with

    app.factory('Position', function($timeout) {
        ...
    });
    
    0 讨论(0)
提交回复
热议问题