Why is my reach undefined?
I have the following html:
I am trying to get the scope as:
console.log("app element scope: " + $('#angularHeaderDiv').scope());
but I got: undefined
.
I am starting out with angular JS and I just don't understand why it doesn't work.
UPDATE : this doesn't work either:
var appElement = document.getElementById('angularHeaderDiv');
console.log("app element scope: " + angular.element(appElement).scope());
UPDATE 2 : All the code where I am trying to print the area in the console:
angular.module('cmApp', [ 'pascalprecht.translate' ])
.config(function($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix : '/resources/angular/scripts/languages/locale-',
suffix : '.json'
});
// add translation table
$translateProvider.preferredLanguage('en');
var appElement = document.getElementById('angularHeaderDiv');
console.log("app element: " + angular.element(appElement).scope());
});
source to share
If you have this in your code:
$compileProvider.debugInfoEnabled(false);
... then scope()
they isolateScope()
will return undefined
. If set to false
, you will notice that other elements such as ng-scope
and ng-isolate-scope
disappear from the attributes class=
for the elements.
See: https://code.angularjs.org/1.3.16/docs/guide/production#disabling-debug-data
source to share
I don't think you actually have scope
. Assuming what you meant $scope
, this is an environment that is shared between the controller and part of your DOM, and is injected inside your controller by AngularJS's dependency injection engine. Also, I don't see any connection between yours '#angularHeaderDiv'
and any scope, since this div is not even associated with any controller.
I'm also not very good at AngularJS, but I have never actually seen what you are trying to do here.
Edit
After seeing your edit where you are trying to access the DOM element internally config
, I would say that this is for sure a non-AngularJS way to solve your problem. I suggest you read more about structure.
source to share