Angular Interview Questions Tutorial
Angular Interview Questions for Experienced
Q. What is a shared module in Angular?
A. Shared moduled is used to put commonly used components, pipes, and directive in one module, so that they can be used by other modules.
Q. What is the difference between pure and impure pipes?
A. By default all pipes are pure. All built-in pipes are pure. It's related to change detection in Angular. Pure pipes will reflect changes only when there is a change in the input. So in case of the input array, if there is any change like the addition or deletion of an array element, then pure pipes will work. But if there is change only in any specific property of the input array (mutation of input), then pure pipes will not reflect changes.
To make pipes reflect changes on mutating the input, we will need to convert it as an impure pipe.
Q. What is HostListener?
A. HostListener is used to capture the DOM element native events, for example detecting DOM element events like "focus", "blur", "mouseover" etc. It's applied as @HostListener decorator.
@HostListener('blur') onBlur() {
console.log("On Blur");
}
Q. What is HostBinding?
A. HostBinding is used to set properties of the DOM native element. For example, if you want to set the class, width, height, etc. of an element, then you will need @HostBinding decorator.
@HostBinding('style.border') border: string;
@HostListener('click') onClick() {
this.border = '5px solid green';
}
Q. What is dynamic components?
A. Dynamic components are the components in which components location in the application is not defined at build time.i.e, They are not used in any angular template. But the component is instantiated and placed in the application at runtime.