javascript控制台与右键单击浏览器并选择inspect?

时间:2021-04-28 20:46:00

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().

我目前正在开发一个角应用程序,并希望看到我在控制台上的范围。我现在通过键入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.

当我通过右键单击页面、选择检查、导航到console选项卡并输入上面的代码时,就可以实现这一功能。

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: http://imgur.com/a/XRBl2

下面我提供了显示不同输出的控制台的屏幕截图:http://imgur.com/a/XRBl2。

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

我找到了一个现场网站,在那里也出现了这种现象,所以你可以自己试试:https://www.google.com/partners/?hl=nl#a_profile;bdgt=;idtf=3245994249;lang=;locn=;motv=0

2 个解决方案

#1


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.

Chrome将检查过的元素的历史记录存储在变量中,从$0开始。这就是为什么只有在元素面板中首先选择它时它才能工作。有像Batarang这样的Chrome开发工具扩展,可以向元素检查器添加一个面板,显示所选元素的范围,这可能对您有帮助。或者,您可以使用angular.element( ).scope()在控制台中获取范围,而不是依赖检查历史。

#2


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

$0在chrome控制台表示最近检查的元素,如果你只是打开chrome控制台,你没有检查任何东西。检查:https://willd.me/posts/0-in-chrome-dev-tools

#1


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.

Chrome将检查过的元素的历史记录存储在变量中,从$0开始。这就是为什么只有在元素面板中首先选择它时它才能工作。有像Batarang这样的Chrome开发工具扩展,可以向元素检查器添加一个面板,显示所选元素的范围,这可能对您有帮助。或者,您可以使用angular.element( ).scope()在控制台中获取范围,而不是依赖检查历史。

#2


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

$0在chrome控制台表示最近检查的元素,如果你只是打开chrome控制台,你没有检查任何东西。检查:https://willd.me/posts/0-in-chrome-dev-tools