NG Interview Set I - API Questions Flashcards

NG Interview Set I - API Questions

1
Q

What does this line do? @HostBinding('[class.valid]') isValid;

A
  • Applies the css class ‘valid’ to whatever is using this directive conditionally based on the value of isValid
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you use renderer methods instead of using native element methods?

A
  • Potentially if you’re rendering to something besides the browser, e.g. rendering native elements on a mobile device, or server side rendering (?)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the point of calling renderer.invokeElementMethod(rendererEl, methodName)?

A
  • To invoke a method on a particular element but avoid direct DOM access (so we don’t tie our code just to the browser)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you control size of an element on resize of the window in a component?

A

``

@HostListener(‘window:resize’, [‘$event’]) onResize(event: any) { this.calculateBodyHeight(); }

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

What would be a good use for NgZone service?

A
  • Running an asynchronous process outside of Angular change detection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you protect a component being activated through the router?

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

How would you insert an embedded view from a prepared TemplateRef?

A

` viewContainerRef.

createEmbeddedView(templateRef);`

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