Angular CoTask Hands-on Flashcards

(18 cards)

1
Q

install angular cli globally

uninstall angular cli globally

A

npm install -g @angular/cli

npm uninstall -g @angular/cli
npm cache clean –force

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

Apply class “host-inactive” on the HTMLElement hosting the component/directive and onClick, set the class to “host-active”.

A

Inside decorator:-
host: {
‘[class]’: ‘classState()’,
‘(click)’: ‘toggleInactive($event)’
}

Inside class:-
protected classState = signal(“host-inactive”);
toggleInactive(event: Event) {
if (this.classState() === “host-inactive”)
this.classState.set(“host-active”);
}

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

What does min-height: 100vh mean?
Why should you apply this style to the root component of your application?

A

100vh means “Make sure the root component is layed out at least as tall as the screen, irrespective of the height of the parent element”.

https://copilot.microsoft.com/shares/VPcezYmajCoCKKmZFProJ

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

difference between min-height: 100vh; and min-height: 100%;

A

min-height: 100vh; means minimum height is 100% of the viewport height.

min-height: 100%; means minimum height is 100% of the parent element’s height.

If you use min-height: 100% without setting height on the parent, your layout might collapse to fit the content.

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

Lazy load the children routes of ‘auth’ feature:

‘auth/login’
‘auth/signup’

so that, auth bundle is not loaded into DOM unless user visits ‘/auth’ route
and
signup bundle is not loaded into DOM if user visits ‘/auth/login’ route.

A

Inside auth.routes.ts:
export const AUTH_ROUTES: Routes = [
{
path: ‘login’,
loadComponent: () => import(‘./components/login/login’).then(m => m.CtLoginComponent),
title: ‘CoTask | Sign In’
},
];

Inside app.routes.ts:
export const routes: Routes = [
{
path: ‘auth’,
// Lazy load the feature routes
loadChildren: () => import(‘./features/auth/auth.routes’).then(m => m.AUTH_ROUTES),
},
];

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

BEM style class names of
1. login component
2. button inside login component
3. disabled button inside login component

A
  1. login
  2. login__btn
  3. login__btn–disabled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Does order of routes matter in Routes array?
If yes, what should be order of
* auth
* /
* ** (wildcard)

A

Yes, Angular router processes routes sequentially, from top to bottom, and uses the first path match it finds.
1. auth
2. /
3. **

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

In my mind questions for HLD

  1. What kind of styles should we apply globally?
  2. Where should we keep styles files that we intend to apply globally?
  3. How to use feature flags in angular?
  4. How and where to load some essential scripts before initializing the app?
  5. What kind of business logic forms the part of such pre-initializing script?
  6. How to implement global error handling to hide stack trace from end user?
  7. How to implement pagination on UI using api from backend?
  8. How to implement infinite scroll?
  9. How to implement multi-page form submission?
  10. When and how to use Form Arrays (instead of FormGroups)
  11. How to implement reusable modal dialog, using content projection ?
  12. How to use indexedDB to avoid hitting api calls on page refresh?
  13. How and when to prefetch data for a route?
  14. How to implement FAQs using accordions?
  15. How to implement typeahead or search suggestions in searchbox?
  16. What’s AOT compilation in Angular?
  17. What’s Artifactory/JFrog, how is it used in Angular?
  18. How to build SSR app in Angular?
  19. Difference between builder and bundler, how each is used in Angular?
  20. How and when to use interceptors in Angular?
  21. How to implement authentication in Angular?
  22. Which pipe did you implement in Angular?
  23. Which directive did you implement in Angular?
  24. How do you manage environment.ts for dev/prod separation in Angular?
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What will be output?
const user = { name: “Sahil” };
user.name = “Copilot”;
console.log(user.name);

A

“Copilot”

If const is used with an object or array, the reference is fixed, but the contents can still be mutated.

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

What will be output?

class User {
readonly id: number;
constructor(id: number) {
this.id = id;
}
}
const u = new User(1);
u.id = 2;
console.log(u.id);

A

Error.

Cannot mutate a readonly property of the class.

const for immutable variables and references (box).
readonly for immutable properties of classes (contents of the box)

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

When to use protected and when to use private?

A
  1. private for injected services, not accessible to subclasses.
  2. protected for FormGroup, accessible to subclasses.
  3. public (by default) for accessible from template and from outside of class.

Angular templates as privileged subclasses of your component. They can call protected methods in event bindings (like a child calling a parent’s protected method), but they can’t read or bind to protected properties directly

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

fb.nonNullable.group()
versus
fb.group()

A
  1. Creates a FormGroup where all controls are non-nullable
    (inferred as FormControl<string>)</string>
  2. Creates a FormGroup where all controls are nullable
    (inferred as FormControl<string | null>)

Using nonNullable eliminates the need for null checks in your code.

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

Manually trigger update to ensure all validations run on a form, especially the cross-field ones.

A

this.signupForm.markAllAsTouched();

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

Get value of email control from the formgroup defined by
fg =this.fb.nonNullable.group({
email: [’’],
password: [’’],
});

A

this.fg.controls.email.value

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

print errors of password form control.

A

console.log(this.loginFormGroup.controls.password.errors);

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

Difference between
<a href="/auth/signup"></a>
and
<a [routerLink]="['/auth/signup']"></a>

A
  1. href would cause a full page reload Angular would lose control.
    * The browser sends a new HTTP request to the server.
    * The entire Angular app is rebooted from scratch.
    * All in-memory state (form data, services, route guards, etc.) is lost.
  2. routerLink avoids full page reload and instead. Angular’s Router intercepts the click and:
    * Updates the URL without reloading the page.
    * Loads the new component in-place.
    * Keeps services, state, and context alive.
    * Triggers route guards, resolvers, and animations as expected.
17
Q

difference between
1. justify-content: center;
and
2. align-items: center;

A
  1. Aligns items horizontally (by default)
  2. Aligns items vertically (by default)