AngularJS和Firebase“$timeout未定义”
AngularJS & Firebase '$timeout is not defined'
嘿伙计们,我刚刚学习了角度JS和Firebase,由于某种原因,当我尝试在以下代码中调用$timeout函数时,我似乎遇到了引用错误:
'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();
});
});
});
我得到这个确切的错误:
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
知道为什么会发生这种情况吗?谢谢,尼克
您需要声明$timeout
才能使用它与以下内容相同:
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();
});
});
});
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- AngularJS和Firebase“$timeout未定义”
- $timeout AngularJS 应用程序中未定义的错误
- AngularJS 使用$timeout给出未定义的错误