How to debug angular applications efficiently? Part — IV

Ramanathan Chockalingam
2 min readMar 15, 2021

ng.getOwningComponent

Usage: ng.getOwningComponent(document.querySelector(“Your element selector”));

GetOwningComponent returns the parent component of the child component which we queried. If there is no parent component then null will be returned.

ng.getOwningComponent API

ng.getRootComponents

Usage: ng.getRootComponents(document.querySelector(“Your element selector”));

This API always returns root components that are bootstrapped by angular.

ng.getRootComponents API

ng.getContext

Usage: ng.getContext(document.querySelector(“Your element selector”));

This will retrieve the embedded context on the element. If there is no embedded context then it will simply return the component instance.

ng.getContext API

ng.getDirectives

Usage: ng.getDirectives(document.querySelector(“Your element selector”));

This API will retrieve all the attribute directives applied to the particular element as an array. Each element in the array is an actual instance of the directive and changing the properties and methods will be reflected accordingly by calling ng.applyChanges

ng.getDirectives API

ng.getHostElement

Usage: ng.getHostElement(document.querySelector(“Your element selector”));

This API will fetch the host HTML element of a component or directive.

ng.getHostElement API

ng.getListeners

Usage: ng.getListeners(document.querySelector(“Your element selector”));

It will list all the event listeners attached to the element and it is the combination of both component and directives events.

ng.getListeners API

--

--