It's the Xinrui Ma


Tag: Angular

Angular 2 Interview Questions & Answers

1. What are Angular Directives? Explain attribute directive.
Directives are instructions which tell angular to do something.
Directives allow you to attach Behaviour to the element in the DOM.

2. How many types of Directives are there in Angular 2?
There are three types of directives in Angular2:
a. Components—directives with a template.
b. Structural directives—change the DOM layout by adding and removing DOM elements.
c. Attribute directives—change the appearance or behavior of an element, component, or another directive.

3. How event are attached to directives?
The @HostListener decorator lets you subscribe to events of the DOM element that hosts an attribute directive

4. How do we pass external data into Directive?
To pass the external data into directive it means we can pass any data from the different component into the directive and it can be done by @input data binding.
Read more.

5. How to handle HTTP error in Angular 2?
You could handle in the component by adding a second callback to the .subscribe():

6. Explain how we pass data in HTTP request?
In addition to fetching data from the server, HttpClient supports mutating requests, that is, sending data to the server with other HTTP methods such as PUT, POST, and DELETE.