Angular intermediate Flashcards

(11 cards)

1
Q

Create a new Angular app with name “Demo” having routing enabled and css syling as scss

A

ng new demo
–routing
–style=scss

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

create a dashboard module having two components:
dashboard & stats

A

ng g m dashboard
ng g c dashboard/dashboard
ng g c dashboard/stats

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

List the configuration parameters of NgModule along with their purpose

A
  1. declarations: Components, Directives and Pipes owned by this module.
  2. imports: other Modules on which it depends
  3. exports: which components/directives/pipes this module exposes
  4. providers: services scoped to this module
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do we import CommonModule in a standalone component?

A
  • For using structural directives like *ngIf, *ngFor
  • For using attribute directives like ngClass, ngStyle
  • For using built-in pipes like date, async etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

to inject HttpClient in your component, which module do you need to import?

Do we need to import it in every component?

A

HttpClientModule

However, we can use
providers: [provideHttpClient()]
in the bootstrapApplication() appconfig parameter in main.ts file. Then, we don’t need to import HttpClientModule in every component.

since version 17

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

How do you lazy-load Dashboard module in app-routing.module.ts?

A

Inside app-routing.module.ts:
{
path: “dashboard”, loadChildren: () => import(./dashboard/dashboard.module)
.then(m => m.DashboardModule)
}

Define DashboardRoutingModule and in @NgModule, use
imports: [RouterModule.forChild(routes)],

Import DashboardRoutingModule inside DashboardModule

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

How do you lazy-load ProfileCardComponent in app.routes.ts?

A

{
path: ‘profile’,
loadComponent: () =>
import(‘./profile-card/profile-card.component’).then(m => m.ProfileCardComponent)
}

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

Explain two usecases when you used effect with signals in Angular.

A
  1. syncing signal state with local storage
    effect(() => { localStorage.setItem(‘chartType’, chartType());
    });
  2. refetch data when user changed category filter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain how computed() works for derived state?

A

const total = computed(() => price() + gst());

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

Benefit(s) of using input() signal over the @Input() decorator

A

No need to handle reactivity manually using ngOnChanges hook.

For simple binding without reactivity, use @Input()

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