0% found this document useful (0 votes)
10 views

Angular Interview Questions

Uploaded by

jayar003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Angular Interview Questions

Uploaded by

jayar003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

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’}
] },

{ path: ‘ ’, pathMatch: 'full', redirectTo: ‘/home/ productList', canActivate: [AuthGuardService] },


];

@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’;

* Get the product Id as the value @Component({


selector: 'app-product-rating’,
* First argument is the rating out of 5 template: `
<h2>Product rating</h2>
* Second Argument is No of reviews for the product <p>
rating: {{ productId }}
*/ </p>
`
@Pipe({name: ‘productRating'}) })
export class ProductRatingPipe implements PipeTransform { export class ProductRatingComponent {
transform(value: string, rating?: number, noOfReviews:number): number
productid = 1234;
{ rating = 4;
Reviews = 1987;
return ‘Product Id ’ + value + ‘has a rating of ’ + rating +
}
‘No of Reviews is’ +noOfReviews;
}
}
Whats your approach
• ProductId
• ProductName
• Category
• Description – you highlight a series of keywords/search Text
• Price
• Discounts
• Reviews
• Description
• Rating
• ProductId => ProductNumber
• ProductName => Name
• Category
• Description => ItemDescription
• Price => Cost
• Discounts => Coupons
• Reviews
• Description
• Rating
Guess the output
of(1, 2, 3, 4).pipe(
map(x => x * 2),
tap( console.log),
take(2),
tap(console.log)
).subscribe();
Guess the output
public class Value {
private static int? value;
public Value()
{ private static void Main(string args[])
value ??= 1; {
}
Value testValue = new Value();
testValue.Print();
static Value()
}
{
value ??= 2;
if (value == 1)
value = 3;
}
public void Print()
{
Console.WriteLine(value ?? 0);
}
}
For Tech Leads
• What are some angular best practices you “recommend” or insist that
you team follows
• What do you look out for in a code review. What are some best
practices you watch out for
• Experience with Angular Libraries

You might also like