Angular Interview Questions
Angular Interview Questions
• State some ways in which components can interact with each other. Like share data between each other?
• What is @ViewChild – This decorator allows you to inject the reference of any element in your template to the component’s class.ViewChild gets
the first matching element, @ViewChildren gets the list of all matching elements
• Angular pipes? Give some examples.
• What is an async pipe/Observables can be consumed only when you subscribe to it. How can I use an observable in the template directly
without bothering to subscribe or unsubscribe/
• Difference between promises and observables – some example scenarios.
• What is a subject – Subject is a special type of observable in the sense its values can be multicasted to many observers and it can also feed new values to its observers like
an event emitter.
• Different types of subjects? – Subject (no initial value), behaviour subject (with initial value), async subject (gives the latest value), replay subject (emits n no of last
values)
• What are angular directives? Component, structural, attribute directive
• Difference between template and reactive forms
• How does routing work in angular? Its basically what makes angular a SPA. It controls what can be shown and hidden in a page without having to go to a server every
single time to get a new page.
• When you specify the list of routes/paths in your routes array - The order of routes in your routes array matters. Why? It goes from most specific to
least specific why? Static path like customer should go before a least specific path like :id. Reason - if you had the :id path above the action-result path, angular would use the
word 'action-result' as the id in the :id path.
• What is the diff between router link and router outlet – With router outlet the only way to use those routes is for the user to manually type the path in the browser's
address bar, with router link directive helps you embed those links into the html within links buttons etc
• What is angular route guard/ What can you use in Angular to lets says authenticate or check user roles and tell your router to allow/not allow
navigation to different routes
• Have you ever made use of Http Interceptors? Difference scenarios where it can be used in angular.
• Best way to replace a nested subscription – Map operators
• Can you state a use case where forkJoin would come in handy
• Is there any difference between using a show/hide to control the visibility of an element vs using an *ngIf
• What would you use ngOnInit for & constructor for? Is it both the same?.
• Is it possible to make use of multiple pipes. How?
• Have you heard of partial type
• Angular life cycle hook
• Difference between const and readonly
• What are extensionMethods
• Advantages of .net core
Guess whats wrong with this code
const routes: Routes = [
{path: '**', component: PageNotFoundComponent},
{ path: ‘home’, component: RootComponent, canActivate: [AuthGuardService],
children: [
{ path: ‘productList', loadChildren: () => import(‘./product/product.module’).then(m => m.ProductModule) },
{ path: ‘orders’, loadChildren: () => import(‘./orders/orders.module’).then(m => m.OrdersModule) },
{ path: ‘ ’, pathMatch: 'full', redirectTo: ‘productList’}
] },
@NgModule({
imports: [RouterModule.forRoot(routes)]
})
Guess the output of the following snippet
of(1, 2, 3, 2, 3, 1, 4)
.pipe(
distinct(),
tap(console.log),
take(2),
tap(console.log)
)
.subscribe();
How to use this pipe
import { Pipe, PipeTransform } from '@angular/core';
/* import { Component } from '@angular/core’;