[Angular 2] How to Debug an Angular 2 application-debugging via Augury or the Console

Source: Internet
Author: User

In this lesson we'll learn several ways to debug a Angular 2 application, including by using Augury and the console. This was especially useful in situations (typically in enterprise development) where we were not administrators on our Machi NE and don ' t has chrome available, our we do has it but is forbidden from installing Chrome extensions.

Select Heroes component in console:

Then if you type $ in console, it'll print out the current component:

This was actually get domelement, what we want are JS object, then we can programme somthing on it.

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

Ng.probe ($). 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 was because Angular 2 change detection.

We need to trigger it by:

// trigger The change detection

Once We run it, the UI would change.

But doing the 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'll immdeticlly reflect on the interface.

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

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

$0.classlist

[Angular 2] How to Debug an Angular 2 application-debugging via Augury or the Console

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.