Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my scope is undefined?

I have the following html:

enter image description here

I am trying to get the scope like:

console.log("app element scope: " + $('#angularHeaderDiv').scope());

but I received: undefined.

I am angularJS beginner and I simply dont' get why this 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 try to print out the scope in 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());
});
like image 696
Cristian Boariu Avatar asked Dec 01 '22 15:12

Cristian Boariu


1 Answers

If you have this in your code:

$compileProvider.debugInfoEnabled(false);

...then scope() and isolateScope() will return undefined. If it's set to false, you'll notice other things like ng-scope and ng-isolate-scope disappearing out of class= attributes on elements.

See: https://code.angularjs.org/1.3.16/docs/guide/production#disabling-debug-data

like image 146
FOO Avatar answered Dec 09 '22 19:12

FOO