Create a new Angular app with name “Demo” having routing enabled and css syling as scss
ng new demo
–routing
–style=scss
create a dashboard module having two components:
dashboard & stats
ng g m dashboard
ng g c dashboard/dashboard
ng g c dashboard/stats
List the configuration parameters of NgModule along with their purpose
Why do we import CommonModule in a standalone component?
to inject HttpClient in your component, which module do you need to import?
Do we need to import it in every component?
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 do you lazy-load Dashboard module in app-routing.module.ts?
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 do you lazy-load ProfileCardComponent in app.routes.ts?
{
path: ‘profile’,
loadComponent: () =>
import(‘./profile-card/profile-card.component’).then(m => m.ProfileCardComponent)
}
Explain two usecases when you used effect with signals in Angular.
Explain how computed() works for derived state?
const total = computed(() => price() + gst());
Benefit(s) of using input() signal over the @Input() decorator
No need to handle reactivity manually using ngOnChanges hook.
For simple binding without reactivity, use @Input()