Angular Dump
Angular Dump
ANS:
.map((res) => {
return res as Object
})
.catch((e) => console.log('Error', e))
.toPromise();
2)
You are writing a unit test in Jasmine for your Angular class. You access the
Angular element using the following code:
fixture.debugElement.query(By.css('h1'));
Appending an ID to a youtube video URL is considered safe in Angular. Which of the
following code snippet can be used to make Angular trust a video URL?
ANS:
updateVideoUrl(id: string) {
this.dangerousVideoUrl = 'https://www.youtube.com/embed/' + id;
this.videoUrl =
this.sanitizer.bypassSecurityTrustResourceUrl(this.dangerousVideoUrl);
}
3) You are working on an Angular 2 project where you wish to inject a window
object into one of the constructors in your code. Which of the following is the
correct way to do this?
ANS:
constructor(@Inject("windowObject") window: Window})
4)
In Angular 2, we need to include <base href="/"> tag. It helps in determining how
to construct the routing information for an application. Assume you are a
developer, but you don't have access to the head section of the application source
page.
5) You are building an application that shows a list of contacts stored in the
contact list component, and when you click on the contact, it navigates to contact
details component. In Angular 2, there are different ways to route to other
components and routes.
Which of the following option shows the correct syntax for adding expression to
access dynamic value?
ANS:
<a [routerLink]="['/contacts', contact.id]">
{{contact.name}}
</a>
Ng-style
Ng-class
ANS: All
8)In the context of XSS, which of the given HTML elements will be treated as
untrusted by default?
<a href="javascript:...">
this.http.get(url)
Considering the standard practice, from which section of a component would you use
service to fetch data from the server?
ANS:
ngOnInit lifecycle hook
10) Module A has a public component (X), directive (Y) and pipe(Z).
Module A is imported in module B.
11) Given that there are 3 modules A, B & C imported into the root module. In a
session, a user navigates through routes only attached to module A. Comment on
which all modules will be loaded in this session.
ANS:
[{
path: 'messages',
component: C1
}, {
path: 'messages/:id',
component: C2
}]
For the path /messages/:id, how would you obtain the value of id parameter inside
the component?
ANS:
Import ActivatedRoute service as X.
X.params.subscribe
14)
A common way of applying filters is to pipe it along with the data in the
interpolation expression ( {{ data | filter }} ). What is the significance of the
pipe here?
ANS:
Pipe streams the output of the left-hand side as the input to the right-hand side.
15) While fetching a response from the server, services generally adopt the
mechanism of an emitting event. Which of the following emits a single cancellable
event?
ANS:
Observables
17) A component implements the OnInit interface. Which of ngOnInit() and the
component constructor will be called first?
ANS: constructor
19) Which of the following directives when set to false does not allow further
execution in child HTML elements?
ANS: ngIf
20)