Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $document vs document在Angular应用程序中的工作方式不同_Javascript_Angularjs_Angular Services - Fatal编程技术网

Javascript $document vs document在Angular应用程序中的工作方式不同

Javascript $document vs document在Angular应用程序中的工作方式不同,javascript,angularjs,angular-services,Javascript,Angularjs,Angular Services,我不明白为什么运行函数中的$document不起作用,而document起作用 这项工作: .run(function($rootScope, $state, $stateParams) { document.addEventListener('deviceready', checkConnection, false); //more code below 这不起作用: .run(function($document, $rootScope, $state, $stateParams)

我不明白为什么运行函数中的
$document
不起作用,而
document
起作用

这项工作:

.run(function($rootScope, $state, $stateParams) {
    document.addEventListener('deviceready', checkConnection, false);
//more code below
这不起作用:

.run(function($document, $rootScope, $state, $stateParams) {
        $document.addEventListener('deviceready', checkConnection, false);
    //more code below
使用angular
$document
服务时,我缺少了什么


谢谢

在注册事件侦听器时,您希望将DOM事件附加到
文档
对象

但是
$document
确实在
0
th索引上有该对象,并且该对象具有其长度,因此您可以通过执行
$document[0]
从$document轻松获取
document

为了更好地使用angular jQLite API,您可以使用
.on

$document.on('deviceready', checkConnection, false);