Angular Dependency Injection Tokens

PunctualElPaso avatar
PunctualElPaso
·
·
Download

Start Quiz

Study Flashcards

82 Questions

What are the major features of Angular?

Declarative templates, dependency injection, end to end tooling

Describe Angular as a framework.

Angular is a completely revived component-based framework where an application is a tree of individual components.

What is the purpose of directives in Angular?

Directives add behavior to an existing DOM element or component instance.

Where can you store a component's template in Angular?

Inline using the template property or in a separate HTML file linked with @Component decorator's templateUrl property.

What is the purpose of NgModule decorator in Angular?

To define logical boundaries in the application and divide it into separate modules.

How does Angular divide the functionality of an application?

By separating the application into different modules.

What is the purpose of ngOnInit in Angular?

To indicate that Angular is done creating the component and for initialization/declaration tasks.

What is the main responsibility of the Constructor in Angular?

To initialize class members and set up Dependency Injection.

Why is it advised not to perform actual 'work' in the constructor of an Angular class?

To keep the constructor focused on initialization and use ngOnInit for actual component setup.

What is the significance of services in Angular applications?

Services provide common functionality to various modules, promoting separation of concerns and modularity.

Explain the purpose of ElementInjector hierarchies in Angular.

ElementInjector hierarchies are created for DOM elements matching Angular components or directives, facilitating dependency injection.

What is the default method in a class that is executed upon instantiation in Angular?

Constructor.

Why is it recommended to use services for common functionality in Angular?

To promote better separation of concerns and modularity by extracting common functionality out of components.

When does Angular call the ngOnInit lifecycle hook?

After Angular is done creating the component.

What is the role of the NullInjector in Angular dependency injection?

To throw an error when dependencies are not found, except when @Optional() decorator is used.

How does Angular handle the registration of services in an application?

Angular creates a root injector where services are registered via the @Injectable annotation.

What is the name of the Angular module that you bootstrap to launch the application?

AppModule

What is the major advantage of using HttpClient in Angular applications?

HttpClient.get() method returns an Observable of typed HttpResponse.

How can you handle errors returned from HttpClient in an Angular component?

By passing an error object as a second callback to the subscribe() method.

What is RxJS used for in Angular applications?

RxJS is used for composing asynchronous and callback-based code in a functional, reactive style using Observables.

What should you do to begin receiving values from an Observable instance?

Subscribe to it by calling the subscribe() method.

What is the purpose of an Observer in RxJS?

An Observer is a consumer of push-based notifications delivered by an Observable.

What is the difference between Promise and Observable?

Promises can only handle a single future value, while Observables can handle multiple values over time.

What is multi-casting in the context of Observables?

Multi-casting is the practice of broadcasting to a list of multiple subscribers in a single execution.

How can you handle errors in Observables using an error callback?

By specifying an error callback on the observer.

What method can accept callback function definitions for next, error, and complete handlers in Observables?

subscribe() method

What is the purpose of the animation transition function in Angular?

To specify the changes that occur between one state and another over a period of time.

How can you inject dynamic HTML, Style, Script, and Url using DomSanitizer?

Using DomSanitizer to inject the dynamic content.

What are some key differences in how dependency injection works between AngularJS and Angular?

Dependency injection is a common component in both, but the implementation differs.

How can you enable Ivy in an existing Angular project?

By adding the enableIvy option in the angularCompilerOptions in the project's tsconfig.app.json.

What are some features you can expect with Ivy preview in Angular?

Faster AOT compilation and the ability to opt for a preview version of Ivy.

How can you add a Web Worker in an Angular application?

By using the ng generate web-worker app command.

What is the purpose of an App Shell in Angular?

To render a portion of the application via a route at build time for faster initial display.

What is the significance of capitalization conventions in Angular?

To distinguish the names of various types within the framework.

What are class field decorators in Angular?

Decorators declared immediately before a field in a class definition.

What is a DI token in Angular?

A lookup token associated with a dependency provider in the dependency injection system.

What determines the type of compilation (JIT or AOT) when running ng build or ng serve commands?

The value of the aot property in the build configuration specified in angular.json.

What error is generated if arrow functions are still used in Angular?

An error node is generated in place of the function.

What does the RouterOutlet directive do?

It acts as a placeholder in the template where the router should display components.

What kind of functions cannot be used to assign values to decorator properties in Angular?

Arrow functions or lambda functions.

How can you access the current RouterState in an Angular application?

You can access it using the Router service and the routerState property.

What is the purpose of the RouterLink directive in Angular?

It gives the router control over anchor tags for navigation paths.

What process does the compiler perform when it evaluates an expression during collection?

Folding.

What are macros supported by the AOT compiler in Angular?

Macros in the form of functions or static methods that return an expression.

Explain the purpose of RouterLinkActive directive.

It toggles CSS classes for active RouterLink bindings based on the current RouterState.

How can you enable binding expression validation in Angular?

By adding the compiler option fullTemplateTypeCheck in the tsconfig.json.

How can you define a wildcard route in Angular?

A wildcard route has a path consisting of two asterisks to match every URL.

How can you implement animation in an Angular project?

By using Angular's state() function to define different states and associated styles.

What is ActivatedRoute used for in Angular?

It contains information about a route associated with a component and can be used to traverse the router state tree.

How should a router be configured with route definitions?

You configure the router with routes via the RouterModule.forRoot() method.

What is the purpose of the style() function in Angular animations?

To define a set of styles to associate with a given state name.

What does Angular Animations provide for single page web applications?

A powerful way to implement sophisticated and compelling animations.

What is the purpose of Ahead-of-Time (AOT) compilation in Angular?

It compiles the Angular app at build time, making it the default starting in Angular 9.

How can you define a state transition in Angular animations?

By specifying a unique name and associated styles using state() and style() functions.

How can custom elements functionality be implemented in Angular?

You can use NgElement and WithProperties types exported from @angular/elements.

What utility functions are provided by the RxJS library for working with observables?

The RxJS library provides utility functions for creating and working with observables.

What is the purpose of Http Interceptors in Angular?

Http Interceptors inspect and transform HTTP requests and responses.

How can you access elements directly in the view in Angular?

You can use the @ViewChild directive.

What is the role of a Subject in RxJS?

Subjects are a special type of Observable that allows multicasting.

How can you report missing translations in Angular?

You can configure Angular compiler to show a warning or an error for missing translations.

What is the purpose of Bazel tool in Angular?

Bazel tool provides advantages like bypassing the Angular CLI builder and running Bazel directly.

What is the context in which an Angular application runs?

A platform is the context in which an Angular application runs, such as a web browser or an operating system.

How does Angular DSL differ from normal HTML?

Angular DSL is a specialized syntax on top of normal HTML that Angular uses.

What happens if custom ids for text messages are not unique?

If custom ids are not unique, the translation units will contain the translation of the first message with that id for all subsequent messages with the same id.

How can you use Angular as a platform-independent framework?

By utilizing the @angular/platform-* packages, Angular can be used as a platform-independent framework.

What is the key advantage of using a Subject over a plain Observable in RxJS?

Subjects are multicast, while plain Observables are unicast.

What is the purpose of the AsyncPipe in Angular?

The AsyncPipe subscribes to an observable or promise and returns the latest value it has emitted.

When should you use inline template and when should you use an external template file in Angular components?

Inline template is usually used for small portions of code, while external template files are preferred for bigger views.

How does Angular handle the innerHtml property binding to prevent XSS vulnerability?

Angular recognizes the value as unsafe and automatically sanitizes it, removing the script tag but keeping safe content.

What is interpolation in Angular and how is it represented?

Interpolation is a special syntax represented by double curly braces {{}} that Angular converts into property binding.

What is a template expression in Angular and how is it used?

A template expression produces a value similar to any Javascript expression and is used in property binding or interpolation.

What is a template statement in Angular and how is it different from a template expression?

A template statement responds to an event raised by a binding target, such as a button click, and is represented by (event)="statement".

What is the purpose of pipes in Angular and how are they used?

Pipes are simple functions that transform data input into a desired output using template expressions.

What are the three categories in which binding types in Angular can be grouped?

Binding types can be grouped into three categories distinguished by the direction of data flow.

How can a pipe be parameterized in Angular?

A pipe can be parameterized by declaring the pipe name with a colon ( : ) followed by the parameter value.

What is the default behavior of the Angular CLI when generating components with templates?

By default, the Angular CLI generates components with a template file.

What is the purpose of the safe navigation operator in Angular?

The safe navigation operator guards against null and undefined values in property paths, preventing null reference errors.

How does the safe navigation operator help in accessing nested properties in Angular?

It allows accessing nested properties without worrying about null reference errors.

When using the JIT compiler in Angular, how can you specify the warning level?

By adding the 'MissingTranslationStrategy' property in the compiler config at bootstrap.

In Angular, if you use the AOT compiler, where should you make changes to the configuration?

Changes should be made in the configurations section of the angular.json file.

Is the @Injectable() decorator mandatory on every service class in Angular?

No, the @Injectable() decorator is not strictly required if the class has other Angular decorators.

What is the alternative name for the safe navigation operator in Angular?

Elvis Operator

Explore the usage of DI Tokens in Angular and learn about the internal token-provider map maintained by the injector. Understand the concepts behind Angular's Domain Specific Language (DSL) for writing Angular-specific syntax in HTML.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser