如何访问在浏览器的控制台中的角* 2 *组件的数据? [英] How to access the *angular 2* components' data in the browser's console?

查看:180
本文介绍了如何访问在浏览器的控制台中的角* 2 *组件的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DisplayComponent,我想看看它在浏览器的控制台数据。我怎么能看出来?

I have a DisplayComponent and I'd like to see it's data in the browser's console. How can I see it?

Angular2一步一步的指导示例:

function DisplayComponent() {
  this.myName = "Alice";
}

我怎么看 this.myName 在浏览器中的控制台

*请注意,这是一个问题关于 2角并没有棱角1. 建议的解决方案AngularJS(角1)不起作用。

* Please note that this is a question about Angular 2 and not Angular 1. The suggested solution for AngularJS (Angular 1) doesn't work.

推荐答案

查看这plunker 。所以基本上你需要在这个时刻做什么:

Check out this plunker. So basically what you need to do at this moment:


  1. 添加 test_lib.js 以页面

  2. ELEMENT_PROBE_BINDINGS 添加到您的应用程序绑定。

  1. Add test_lib.js to the page
  2. Add ELEMENT_PROBE_BINDINGS to your app bindings.

import { bootstrap } from 'angular2/angular2'
import { ELEMENT_PROBE_BINDINGS} from 'angular2/debug'
import { App } from './app'

bootstrap(App,ELEMENT_PROBE_BINDINGS )
    .catch(err => console.error(err));


  • 使用 ng.probe 方法来检查元素:

    const app = document.querySelector('my-app');
    const debugElement = ng.probe(app);
    


  • 这篇关于如何访问在浏览器的控制台中的角* 2 *组件的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆