3

Any node in the scope can be outputted like this:

{{variable}}

could you output the entire scope somehow? something like

{{$scope}}
Himmators
  • 14,278
  • 36
  • 132
  • 223

3 Answers3

1

As a proof of concept, I created a directive to pretty-print the current scope.

You may use it anywhere, simply by adding <scope /> into the template.

Please note that this is just an idea and has several issues:

  1. It depends on ngSanitize to make ng-bind-html work.
  2. It executes prettyScope() several times within an $apply() so it may become sluggish when $scope objects are large and/or have many chained updates (I guess).

The out-of-this-world implementation of syntaxHighlight is taken from here.

Full code and some scope inheritance and isolate scope cases on this plunker.

Community
  • 1
  • 1
Kos Prov
  • 4,207
  • 1
  • 18
  • 14
0

Sure.

$scope.scope = $scope

{{scope}}

Yet, just out of curiosity, why would you do that?

Edit

I didn't test this before answering. Mea culpa. This seems not to work, i get a string of "$SCOPE".

However, as mentioned in the comments, shouldn't console.dir() do the job?

Wottensprels
  • 3,307
  • 2
  • 29
  • 38
-1

Of course it is! Check out this Plunkr.

Since $scope references itself, you need to use an altered stringify method. Thanks to this post for that!

But another great option for exploring the scope is Batarang. Check it out! Unfortunately it's only for chrome.

Community
  • 1
  • 1
Sam P
  • 1,821
  • 13
  • 26
  • Yep! Check my edited post for a plunkr of how to display the $scope. – Sam P May 27 '14 at 14:19
  • 1
    If you're a Firefox user, checkout a small Firebug extension called [AngScope](https://addons.mozilla.org/en-US/firefox/addon/angscope-simple-angularjs-s/) I've written. It helps you inspect `$scope` objects into Firebug's DOM inspector. – Kos Prov May 27 '14 at 14:42