I am new to Angular.js
. I am trying to inject $document
to retrieve the <head>
element in the HTML document:
app.run(function($scope, $document) {
var headRetr = $document.find("head");
if ( headRetr === null ) {
console.log("head not found");
} else {
console.log("head found");
}
});
When I start my application and open the console, I see an error message:
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
What am I doing wrong? I am on angular 1.4.1
.
Change your .run
to this:
app.run(function($document) {
});
There's no $scope
available in .run
. You're not even using it.