Angular 2: How enable debugging in angular2 from b

2020-06-19 06:17发布

问题:

In AngularJS, we have a function called reloadWithDebugInfo()

angular.reloadWithDebugInfo()

which reload the current application with debug information turned on. One can execute this function in browser console and enable the debugging. I am looking for it's equivalent in Angular 2 which can let us enable debugging in developer console. But it seems like there's no equivalent function of this which can be accessed in the browser console. I know there are functions like enableDebugTools and disableDebugTools which let us enable and disable the debugging but one can not access them in browser console. And also to get access to angular2's debugging weapons like ng & ng.probe, one has to enable debug tools first as written in the Angular 2 Application Debugging Guide:

Make sure your application has production mode disabled so that you can have access to the all the methods described below.

I just want to know Is there any way to enable debug tool using console in Angular 2?

回答1:

Debugging info is enabled by default during development in Angular2.

Debugging tools need to be enabled with enableDebugTools

For production enableProdMode() should be called to get rid of debug information that slows down your application and increases code size.

For details how to access debug info from the console see how to access Angular2 component specific data in console?

https://augury.angular.io/ provides a browser Plugin with a graphical UI

Because an Angular application is built for deployment, the options need to be enabled when the application is built, otherwise it won't be included in the deployable.