[Angular 2] How To Debug An Angular 2 Application - Debugging via Augury or the Console

In this lesson we will learn several ways to debug an Angular 2 application, including by using Augury and the console. This is especially useful in situations (typically in enterprise development) where we are not administrators on our machine and don't have Chrome available, our we do have it but are forbidden from installing Chrome extensions.

 

Select heroes component in console:

 

Then if you type $0 in console, it will print out current component:

This is actually get DOMElement, what we want is JS object, then we can programme somthing on it.

 

Todo this, we need to use one comand to get the component instance:

ng.probe($0).componentInstance  // get component instance

 

Now we get the object, lets try to change the Hero which id = 1, change the name to "Superman".

We changed value in console, but it doesn't refect on UI. This is because Angular 2 Change detection.

 

We need to trigger it by:

ng.probe($0)._debugInfo._view.changeDetectorRef.detectChanges() // trigger the change detection

Once we run it, the UI will change.

 

But doing this is lots of work, we can use Augury. You can install it from Chrome extension.

 

Then you can get a more user friendly interface:

You can chang value and it will immdeticlly reflect on the interface.

 

 

-----------------------

If you want to check the class if componet use, you can do:

$0.classList

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值