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
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 (?)
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)
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(); }
5
Q
What would be a good use for NgZone service?
A
- Running an asynchronous process outside of Angular change detection
6
Q
How would you protect a component being activated through the router?
A
- Route Guards
7
Q
How would you insert an embedded view from a prepared TemplateRef?
A
` viewContainerRef.
createEmbeddedView(templateRef);
`