host
Using the host property, you can obtain the instance of the element's host component. This is useful for accessing the data and methods of its host component from within the component.
Below is an example demonstrating how to use the host property to get an instance of the host component:
Username: {{username}}
Response: {{response}}
In this example, we create a custom component user-card, and access the host component's (page's) method sayHi from within the component via this.host, achieving interaction between the component and the host.
If the element is not within a component or page module, the value of host will be null. For example:
-
I am target
-
In this example, the #target element is under the body and not inside any component or page, so the value of $("#target").host is null.