2

I am currently developing an angular app and wish to see my scope in the console. I currently achieve this by typing angular.element($0).scope().

This works when i open the console by right clicking the page, selecting inspect, navigate to the console tab and enter the code above.

however the same line of code does not work when i open the console by using the browser shortcut.

why does this happen and how can i make it so that when i open the browser through a short cut the line of code works ?

Below i have provided screenshots of the console displaying the different outputs: https://i.stack.imgur.com/h5M8R.jpg

I have found a live website where this phenomenon also occurs so you can try it for yourself : https://www.google.com/partners/?hl=nl#a_profile;bdgt=;idtf=3245994249;lang=;locn=;motv=0

Alexander Nied
  • 12,804
  • 4
  • 25
  • 45
duck
  • 1,674
  • 2
  • 16
  • 26

2 Answers2

2

Chrome stores the history of inspected elements in variables it creates starting with $0. That's why it only works if you select it first in the elements panel. There are Chrome Dev Tool extensions like Batarang that add a panel to your element inspector showing the scope for the selected element that would probably be helpful for you. Alternately, you can target the element using angular.element(<SOME_SELECTOR_HERE>).scope() to get the scope in the console, rather than relying on the inspection history.

Alexander Nied
  • 12,804
  • 4
  • 25
  • 45
0

$0 in chrome console means most recent inspected element, if you just open the chrome console, you haven't inspected anything. Check: https://willd.me/posts/0-in-chrome-dev-tools

Rumpelstinsk
  • 3,107
  • 3
  • 30
  • 57