how to access Angular2 component specific data in console?

后端 未结 4 1333
萌比男神i
萌比男神i 2020-11-30 02:54

Is there any way to access Angular2 specific component specific data in console, for debugging purpose?

Like Angular1 has capability to access its components value i

4条回答
  •  盖世英雄少女心
    2020-11-30 03:31

    First select the element using chrome 'inspect element' and run below method in chrome 'developer console'.

    ng.probe($0).componentInstance
    

    You could also use a css selector as shown below.

    ng.probe($$('.image-picker')[0]).componentInstance
    

    If you do it often, to make it little easier, have a global shortcut created as below. Now select any DOM element inside the component using 'inspect element' and invoke 'e()' from console

    window['e'] = () => eval('ng.probe($0).componentInstance');
    

提交回复
热议问题