Fundamentals Flashcards

1
Q

DI two main roles

A

dependency consumer and dependency provider
Angular facilitates the interaction between dependency consumers and dependency providers using an abstraction called Injector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happen when a dependency is requested

A

When a dependency is requested, the injector checks its registry to see if there is an instance already available there.

If not, a new instance is created and stored in the registry. Angular creates an application-wide injector (also known as the “root” injector) during the application bootstrap process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Providing a dependency

A

@Injectable
and then:

The next step is to make it available in the DI by providing it. A dependency can be provided in multiple places:

  1. Preferred: At the application root level using providedIn.
  2. At the Component level.
  3. At the application root level using ApplicationConfig.
  4. NgModule based applications.

like:
@Injectable({
providedIn: ‘root’
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

DI at component level

A

You can provide services at @Component level by using the providers field of the @Component decorator.

In this case the HeroService becomes available to all instances of this component and other components and directives used in the template.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Injecting/consuming a dependency

A

The most common way to inject a dependency is to declare it in a class constructor

When Angular creates a new instance of a component, directive, or pipe class, it determines which services or other dependencies that class needs by looking at the constructor parameter types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

<ng-container>
</ng-container>

A

is a special element in Angular that groups multiple elements together or marks a location in a template without rendering a real element in the DOM.

You can apply directives to <ng-container> to add behaviors or configuration to a part of your template.</ng-container>

Angular ignores all attribute bindings and event listeners applied to <ng-container>, including those applied via directive.</ng-container>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

<ng-content>
</ng-content>

A

<ng-content> is a special element that accepts markup or a template fragment and controls how components render content. It does not render a real DOM element.
</ng-content>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Deferred loading with @defer

A

Deferrable views, also known as @defer blocks, reduce the initial bundle size of your application by deferring the loading of code that is not strictly necessary for the initial rendering of a page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are signals?

A

A signal is a wrapper around a value that notifies interested consumers when that value changes

Signals can contain any value, from primitives to complex data structures.

You read a signal’s value by calling its getter function, which allows Angular to track where the signal is used.

Signals may be either writable or read-only.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Writable signals

A

Writable signals provide an API for updating their values directly. You create writable signals by calling the signal function with the signal’s initial value:

const count = signal(0);
// Signals are getter functions - calling them reads their value.
console.log(‘The count is: ‘ + count());

To change the value of a writable signal, either .set() it directly:

or use the .update() operation to compute a new value from the previous one:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Computed signals

A

Computed signal are read-only signals that derive their value from other signals. You define computed signals using the computed function and specifying a derivation:

const count: WritableSignal<number> = signal(0);
const doubleCount: Signal<number> = computed(() => count() * 2);</number></number>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Loading of computed signals

A

Computed signals are both lazily evaluated and memoized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to create custom pipe?

A

implements PipeTransform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly