FrontendDeveloper.in

Angular Interview Questions

  • Question 213

    What is an entry component?

    An entry component is any component that Angular loads imperatively(i.e, not referencing it in the template) by type. Due to this behavior, they can’t be found by the Angular compiler during compilation. These components created dynamically with ComponentFactoryResolver.

    Basically, there are two main kinds of entry components which are following -

    1. The bootstrapped root component
    2. A component you specify in a route
  • Question 214

    What is a bootstrapped component?

    A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process or application launch time. Generally, this bootstrapped or root component is named as AppComponent in your root module using bootstrap property as below.

    @NgModule({
    declarations: [
    AppComponent
    ],
    imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    AppRoutingModule
    ],
    providers: [],
    bootstrap: [AppComponent] // bootstrapped entry component need to be declared here
    })
    
  • Question 215

    How do you manually bootstrap an application?

    You can use ngDoBootstrap hook for a manual bootstrapping of the application instead of using bootstrap array in @NgModule annotation. This hook is part of DoBootstrap interface.

    interface DoBootstrap {
    ngDoBootstrap(appRef: ApplicationRef): void
    }
    

    The module needs to be implement the above interface to use the hook for bootstrapping.

    class AppModule implements DoBootstrap {
    ngDoBootstrap(appRef: ApplicationRef) {
    appRef.bootstrap(AppComponent); // bootstrapped entry component need to be passed
    }
    }
    
  • Question 217

    What is a routed entry component?

    The components referenced in router configuration are called as routed entry components. This routed entry component defined in a route definition as below,

    const routes: Routes = [
    {
    path: '',
    component: TodoListComponent // router entry component
    }
    ];
    

    Since router definition requires you to add the component in two places (router and entryComponents), these components are always entry components.

    Note: The compilers are smart enough to recognize a router definition and automatically add the router component into entryComponents.

  • Question 218

    Why is not necessary to use entryComponents array every time?

    Most of the time, you don't need to explicitly to set entry components in entryComponents array of ngModule decorator. Because angular adds components from both @NgModule.bootstrap and route definitions to entry components automatically.

  • Question 219

    Do I still need to use entryComponents array in Angular9?

    No. In previous angular releases, the entryComponents array of ngModule decorator is used to tell the compiler which components would be created and inserted dynamically in the view. In Angular9, this is not required anymore with Ivy.

  • Question 220

    Is it all components generated in production build?

    No, only the entry components and template components appears in production builds. If a component isn't an entry component and isn't found in a template, the tree shaker will throw it away. Due to this reason, make sure to add only true entry components to reduce the bundle size.

  • Question 221

    What is Angular compiler?

    The Angular compiler is used to convert the application code into JavaScript code. It reads the template markup, combines it with the corresponding component class code, and emits component factories which creates JavaScript representation of the component along with elements of @Component metadata.

  • Question 223

    How does angular finds components, directives and pipes?

    The Angular compiler finds a component or directive in a template when it can match the selector of that component or directive in that template. Whereas it finds a pipe if the pipe's name appears within the pipe syntax of the template HTML.

  • Question 224

    Give few examples for NgModules?

    The Angular core libraries and third-party libraries are available as NgModules.

    1. Angular libraries such as FormsModule, HttpClientModule, and RouterModule are NgModules.
    2. Many third-party libraries such as Material Design, Ionic, and AngularFire2 are NgModules.
  • Question 225

    What are feature modules?

    Feature modules are NgModules, which are used for the purpose of organizing code. The feature module can be created with Angular CLI using the below command in the root directory,

    ng generate module MyCustomFeature //
    

    Angular CLI creates a folder called my-custom-feature with a file inside called my-custom-feature.module.ts with the following contents

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    
    @NgModule({
    imports: [
    CommonModule
    ],
    declarations: []
    })
    export class MyCustomFeature { }
    

    Note: The "Module" suffix shouldn't present in the name because the CLI appends it.

Get LinkedIn Premium at Rs 399