[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
时间: 2024-12-28 08:29:57

[Angular 2] How To Debug An Angular 2 Application - Debugging via Augury or the Console的相关文章

How to debug an Angular 2 application with Chrome and VS Code

by Fabian Gosebrink on October 16, 2016 in Angular ? 0 Comments In this blogpost I want to show you how to debug an Angular 2 application with Chrome and VS Code. First of all you need to install the extension in VS Code. You can find it here https:/

[Angular 2 Router] Configure Your First Angular 2 Route

Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and then importing the configured RouterModule into your main App Module. Use the Wiki Search as example project. Create a HomeComponent to contain every

Angular项目构建指南 - 不再为angular构建而犹豫不决(转)

如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余前端框架最大的不同,在于它的核心不再是DOM,而是数据,是model.我们惯用的不管是单纯的jQuery还是MVC的Backbone,它们本质仍是让我们更方便更有条理的操作DOM,但是Angular不是.通过一系列魔术般的手法,它将一切的重心转移到数据上.以开发应用而不是操作节点的方式去开发Web,

[从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应用. 需求 需求大概是这样的: 开一个新的 Angular 项目,并且一开始选择加入 Router 功能 根组件是 AppComponent ,然后下方有三个子组件分别是 page1 page2 page3 可以在 AppComponent 内点击连结切换到这三个页面 参考文档: 路由与导航 Rou

[Angular] Bind async requests in your Angular template with the async pipe and the "as" keyword

Angular allows us to conveniently use the async pipe to automatically register to RxJS observables and render the result into the template once the request succeeds. This has some drawbacks, especially if we want to bind the same data in multiple par

[Angular 2] A Simple Form in Angular 2

When you create a Form in Angular 2, you can easily get all the values from the Form using ControlGroup and Controls. Bind [ng-form-model] to the <form> form bind to ControlGoup Bind [ng-form-control] to the <input> input bind to Gontrol impor

[Angular 2] Share a Service Across Angular 2 Components and Modules

Services are used to share data between components. They follow a module pattern that allows you to use the data throughout your application so that your data is consistent and in sync. Create a service.module.ts: import { NgModule} from '@angular/co

angular源码分析:图解angular的启动流程

今天做了一些图来说明angular,由于angular实在太复杂了,不知道用什么图表示比较好,所以就胡乱画了一些,希望有人能看得懂. 一.源码文件编译合并顺序图 二.angular.module函数功能图 三.publishExternalAPI函数功能图 四.注入器工厂函数createInjector内部的providerCache和instanceCache

《Getting MEAN with Mongo Express Angular and Node》---ch08 Adding Angular components to an Express application(向Express应用添加Angular组件)

This chapter covers(本章概要)■ Getting to know Angular(了解Angrular)■ Adding Angular to an existing page(向动态页面添加Angular)■ Filtering lists of data(过滤列表数据)■ Using an API for reading data(使用API读取数据)■ Some Angular jargon: controllers, scope, filters,directives