FrontendDeveloper.in

Angular Interview Questions

  • Question 121

    What is a builder?

    A builder function is a function that uses the Architect API to perform a complex process such as "build" or "test". The builder code is defined in an npm package. For example, BrowserBuilder runs a webpack build for a browser target and KarmaBuilder starts the Karma server and runs a webpack build for unit tests.

  • Question 122

    How do you invoke a builder?

    The Angular CLI command ng run is used to invoke a builder with a specific target configuration. The workspace configuration file, angular.json, contains default configurations for built-in builders.

  • Question 123

    How do you create app shell in Angular?

    An App shell is a way to render a portion of your application via a route at build time. This is useful to first paint of your application that appears quickly because the browser can render static HTML and CSS without the need to initialize JavaScript. You can achieve this using Angular CLI which generates an app shell for running server-side of your app.

    ng generate appShell [options] (or)
    ng g appShell [options]
    
  • Question 124

    What are the case types in Angular?

    Angular uses capitalization conventions to distinguish the names of various types. Angular follows the list of the below case types.

    1. camelCase : Symbols, properties, methods, pipe names, non-component directive selectors, constants uses lowercase on the first letter of the item. For example, "selectedUser"
    2. UpperCamelCase (or PascalCase): Class names, including classes that define components, interfaces, NgModules, directives, and pipes uses uppercase on the first letter of the item.
    3. dash-case (or "kebab-case"): The descriptive part of file names, component selectors uses dashes between the words. For example, "app-user-list".
    4. UPPER_UNDERSCORE_CASE: All constants uses capital letters connected with underscores. For example, "NUMBER_OF_USERS".
  • Question 125

    What are the class decorators in Angular?

    A class decorator is a decorator that appears immediately before a class definition, which declares the class to be of the given type, and provides metadata suitable to the type

    The following list of decorators comes under class decorators,

    1. @Component()
    2. @Directive()
    3. @Pipe()
    4. @Injectable()
    5. @NgModule()
  • Question 126

    What are class field decorators?

    The class field decorators are the statements declared immediately before a field in a class definition that defines the type of that field. Some of the examples are: @input and @output,

    @Input() myProperty;
    @Output() myEvent = new EventEmitter();
    
  • Question 127

    What is declarable in Angular?

    Declarable is a class type that you can add to the declarations list of an NgModule. The class types such as components, directives, and pipes comes can be declared in the module. The structure of declarations would be,

    declarations: [
    YourComponent,
    YourPipe,
    YourDirective
    ],
    
  • Question 129

    What is a DI token?

    A DI token is a lookup token associated with a dependency provider in dependency injection system. The injector maintains an internal token-provider map that it references when asked for a dependency and the DI token is the key to the map. Let's take example of DI Token usage,

    const BASE_URL = new InjectionToken<string>('BaseUrl');
    const injector =
    Injector.create({providers: [{provide: BASE_URL, useValue: 'http://some-domain.com'}]});
    const url = injector.get(BASE_URL);
    
  • Question 130

    What is Angular DSL?

    A domain-specific language (DSL) is a computer language specialized to a particular application domain. Angular has its own Domain Specific Language (DSL) which allows us to write Angular specific html-like syntax on top of normal html. It has its own compiler that compiles this syntax to html that the browser can understand. This DSL is defined in NgModules such as animations, forms, and routing and navigation.

    Basically you will see 3 main syntax in Angular DSL.

    1. (): Used for Output and DOM events.
    2. []: Used for Input and specific DOM element attributes.
    3. *: Structural directives(*ngFor or *ngIf) will affect/change the DOM structure.
  • Question 131

    What is an RxJS Subject in Angular?

    An RxJS Subject is a special type of Observable that allows values to be multicasted to many Observers. While plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable), Subjects are multicast.

    A Subject is like an Observable, but can multicast to many Observers. Subjects are like EventEmitters: they maintain a registry of many listeners.

    import { Subject } from 'rxjs';
    
    const subject = new Subject<number>();
    
    subject.subscribe({
    next: (v) => console.log(`observerA: ${v}`)
    });
    subject.subscribe({
    next: (v) => console.log(`observerB: ${v}`)
    });
    
    subject.next(1);
    subject.next(2);
    
  • Question 132

    What is Bazel tool?

    Bazel is a powerful build tool developed and massively used by Google and it can keep track of the dependencies between different packages and build targets. In Angular8, you can build your CLI application with Bazel. Note: The Angular framework itself is built with Bazel.

  • Question 133

    What are the advantages of Bazel tool?

    Below are the list of key advantages of Bazel tool,

    1. It creates the possibility of building your back-ends and front-ends with the same tool
    2. The incremental build and tests
    3. It creates the possibility to have remote builds and cache on a build farm.
  • Question 134

    How do you use Bazel with Angular CLI?

    The @angular/bazel package provides a builder that allows Angular CLI to use Bazel as the build tool.

    1. Use in an existing application: Add @angular/bazel using CLI
    ng add @angular/bazel
    
    1. Use in a new application: Install the package and create the application with collection option
    npm install -g @angular/bazel
    ng new --collection=@angular/bazel
    

    When you use ng build and ng serve commands, Bazel is used behind the scenes and outputs the results in dist/bin folder.

  • Question 135

    How do you run Bazel directly?

    Sometimes you may want to bypass the Angular CLI builder and run Bazel directly using Bazel CLI. You can install it globally using @bazel/bazel npm package. i.e, Bazel CLI is available under @bazel/bazel package. After you can apply the below common commands,

    bazel build [targets] // Compile the default output artifacts of the given targets.
    bazel test [targets] // Run the tests with *_test targets found in the pattern.
    bazel run [target]: Compile the program represented by target and then run it.
    
Get LinkedIn Premium at Rs 399