1

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.com/');
    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

1 Answer 1

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.com/');
    var childRef = rootRef.child('message');

    childRef.on('value', function(snapshot){
      $timeout(function() {
        var snapshotVal = snapshot.val();
        console.log(snapshotVal);
        $scope.message = snapshot.val();
      });
    });
  });
Sign up to request clarification or add additional context in comments.

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.