在Angular.js中注入$ document时出现未捕获的错误

时间:2015-07-15 17:38:19

标签: javascript angularjs html-head

我是Angular.js的新手。我正在尝试注入$document以检索HTML文档中的<head>元素:

app.run(function($scope, $document) {

    var headRetr = $document.find("head");

    if ( headRetr === null ) {
        console.log("head not found");
    } else {
        console.log("head found");
    }

});

当我启动应用程序并打开控制台时,我看到一条错误消息:

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.4.1/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope(anonymous function)
@ angular.js:38(anonymous function)
@ angular.js:4255d
@ angular.js:4402(anonymous function)
@ angular.js:4260d
@ angular.js:4402e
@ angular.js:4434(anonymous function)
@ angular.js:4265n
@ angular.js:336db
@ angular.js:4265d
@ angular.js:1621zc
@ angular.js:1642Yd
@ angular.js:1536(anonymous function)
@ angular.js:28289a
@ angular.js:2989c
@ angular.js:3264

我做错了什么?我在angular 1.4.1

1 个答案:

答案 0 :(得分:1)

将您的.run更改为:

app.run(function($document) {

});

$scope中没有.run可用。你甚至没有使用它。

相关问题