$timeout AngularJS 应用程序中未定义的错误
$timeout not defined error in AngularJS app
我有以下代码:
app.factory('Position', ['$timeout', function() {
var position = {
latitude: 44,
longitude: 26
};
console.log("Timeout started");
$timeout(function() {
position.latitude += 15;
position.longitude += 15;
}, 2000);
return position;
}]);
我在Javascript控制台中得到了$timeout not defined
。我没有正确注入服务的依赖关系吗?
您没有注入$timeout
.它应该如下。
app.factory('Position', ['$timeout', function($timeout) {
...
}]);
这种方式的声明可确保在 JavaScript 代码被缩小时正确识别服务。有关这如何帮助缩小的更多信息,请参阅关于缩小和声明用于缩小的 AngularJS 模块的说明
如果您的计划中没有缩小(例如快速测试),您可以简单地使用
app.factory('Position', function($timeout) {
...
});
相关文章:
- chrome.storage.sync未定义错误
- 对象为null或IE9中存在未定义错误
- 已定义变量出现未定义错误
- 'define' 在 RequireJS 和 Webapp Yo 生成器上未定义错误
- onreadystatechange未定义错误
- 在CoffeeScript文件上运行Jasmine测试时,对象未定义错误
- 如何修复JSlint报告的“foo未定义”错误
- 无法仅在活动服务器上读取未定义错误的属性“top”
- 主干无法读取属性'属性'主干视图中的未定义错误
- 如何克服javascript中的未定义错误
- require未定义错误
- 单击链接时出现函数未定义错误
- 函数为未定义错误
- 主干未定义错误
- 使用Javascript打印HTML:未定义错误
- 避免“无法读取”属性'获取'的未定义错误
- 未捕获类型错误的coffescription:无法读取属性'offsetWidth'的未定义错误
- ajax上get函数内部的未定义错误
- Javascript变量未定义错误
- AngularJS指令作用域未解析(“属性名称未定义”错误)