最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS & Firebase '$timeout is not defined' - Stack Overflow

programmeradmin4浏览0评论

Hey guys I have just been learning about angular JS and Firebase and for some reason I seem to be getting a Reference Error when I try to call the $timeout function in the following code:

'use strict';

/**
 * @ngdoc function
 * @name drivenApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the drivenApp
 */
angular.module('drivenApp')
  .controller('MainCtrl', function ($scope) {
    var rootRef = new Firebase('/');
    var childRef = rootRef.child('message');

    childRef.on('value', function(snapshot){
      $timeout(function() {
        var snapshotVal = snapshot.val();
        console.log(snapshotVal);
        $scope.message = snapshot.val();
      });
    });
  });

I get this exact error:

Uncaught ReferenceError: $timeout is not defined(anonymous function) @ main.js:16(anonymous function) @ firebase.js:202gc @ firebase.js:52cc @ firebase.js:30dc @ firebase.js:29h.Kb @ firebase.js:221h.Ld @ firebase.js:189Fh.Ld @ firebase.js:179(anonymous function) @ firebase.js:177zh @ firebase.js:171La.onmessage @ firebase.js:170

Any idea why this might be happening? Thanks, Nick

Hey guys I have just been learning about angular JS and Firebase and for some reason I seem to be getting a Reference Error when I try to call the $timeout function in the following code:

'use strict';

/**
 * @ngdoc function
 * @name drivenApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the drivenApp
 */
angular.module('drivenApp')
  .controller('MainCtrl', function ($scope) {
    var rootRef = new Firebase('https://vivid-torch-5432.firebaseio./');
    var childRef = rootRef.child('message');

    childRef.on('value', function(snapshot){
      $timeout(function() {
        var snapshotVal = snapshot.val();
        console.log(snapshotVal);
        $scope.message = snapshot.val();
      });
    });
  });

I get this exact error:

Uncaught ReferenceError: $timeout is not defined(anonymous function) @ main.js:16(anonymous function) @ firebase.js:202gc @ firebase.js:52cc @ firebase.js:30dc @ firebase.js:29h.Kb @ firebase.js:221h.Ld @ firebase.js:189Fh.Ld @ firebase.js:179(anonymous function) @ firebase.js:177zh @ firebase.js:171La.onmessage @ firebase.js:170

Any idea why this might be happening? Thanks, Nick

Share Improve this question asked Feb 20, 2016 at 16:51 Nicholas MaddrenNicholas Maddren 1555 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You need declare $timeout to use it same as:

angular.module('drivenApp')
  .controller('MainCtrl', function ($scope, $timeout) {
    var rootRef = new Firebase('https://vivid-torch-5432.firebaseio./');
    var childRef = rootRef.child('message');

    childRef.on('value', function(snapshot){
      $timeout(function() {
        var snapshotVal = snapshot.val();
        console.log(snapshotVal);
        $scope.message = snapshot.val();
      });
    });
  });
发布评论

评论列表(0)

  1. 暂无评论