[英]Is there a way to print value in variable in angular4 component from console?
I save simple key in a variable in a component using angular 4, when the app closed every value will erased and i know it. 我使用角度4将简单键保存在组件中的变量中,当应用关闭时,每个值都将被擦除,我知道。
this is a simple sample : 这是一个简单的示例:
export class LoginComponent implements OnInit {
data : any;
constructor() {
this.data = "Hello";
}
}
I just want to know is there a way using browser console to show value in this.data
without console.log()
? 我只想知道有没有一种方法可以使用浏览器控制台在没有console.log()
情况下在this.data
显示值?
Yes you can. 是的你可以。
Start by finding some HTML that belongs to your component in your page. 首先找到页面中属于您组件的一些HTML。 Then, inspect it. 然后,检查它。
In Chrome, you will see a $0
besides it. 在Chrome浏览器中,除此以外,您还会看到$0
。 That's a variable reference . 那是一个变量引用 。
Now, go into your console and type 现在,进入控制台并输入
ng.probe($0).componentInstance
This will log you your whole component, with the variables that are in it. 这将记录您的整个组件及其中的变量。 You can simply give it a reference 您可以简单地给它一个参考
const myRef = ng.probe($0).componentInstance
Then delete your component as you want, and log it again from the console directly 然后根据需要删除组件,然后直接从控制台再次登录
console.log(myRef) // or shorthand
myRef
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.