devquora Devquora is a online network of developers basically a (Developer 2 developer Network) for solving problems day to day common code problems of software developer and programmers. Here anyone can register free any share his/ her programming related problems and questions. On Ddevquora, you can also f 8685 Views

Angular 4 interview questions

Angular 4 interview questions

Below are the list of top 20 Angular 4 interview questions with their answers

  1. Explain Component Decorators in Angular 4?
  2. Please provide CLI command to generate a Component in Angular 4?
  3. How to create an Angular 4 Project?
  4. Explain component directory structure of Angular 4?
  5. What is an interpolation in Angular 4?
  6. What are different ways to use a template in Angular 4?
  7. Explain Ng-for directive with an example?
  8. What is different between directive and component in Angular Js?
  9. How to use the ternary operator in Angular Js?
  10. Explain Ng-if directive with an example?
  11. What is property binding or one way binding in Angular js?
  12. Explain how to bind an event in Angular 4 with an example?
  13. Explain services in Angular Js? How to generate and use a service in Angular?
  14. How Angular 4 is different from Angular 2?
  15. What is Isolated Unit Tests?
  16. What is router? and why is it used?
  17. Describe Component lifecycle hooks.
  18. How to apply Custom validation to angular form?
  19. What is difference between Structural and Attribute directives?
  20. How to apply Custom validation to angular form?
  21. How to include an external css in Angular 4?

Q1. Explain component decorators in Angular4.

A decorator is the core concept when developing an angular framework with version 2 and above. It may become a core language feature for JavaScript soon. In angular 4, decorators are used extensively and are also used to compile a code. There are 4 different types of decorators:

  • Class decorators
  • Property decorators
  • Method decorators
  • Parameter decorators

A decorator is a function that is invoked with a prefixed “@” symbol and is immediately followed by a class, parameter, method, or property. A decorator returns the same thing which was given as an input but in an augmented form.

Q2. Write the CLI command to generate a component in Angular4.

Components are just simple classes which are declared as components with the help of component decorators.

It becomes easy to create an application which already works, with the help of angular CLI commands. "Ng generate" is used to generate components, routes, services, and pipes. Simple test shells are also created with the help of this CLI command. For generating a component in angular4 with the help of CLI command, you need to follow the following syntax-

  • ng generate component component_name;

It generates the component and adds the component to module declarations.

 Q3. Explain the component directory structure of angular4.

Here are the elements which are present in the component directory structure anf modules: -

  • module.ts- in this, the angular module is declared. @NgModule decorator is used which initializes the different aspects of angular applications. AppComponent is also declared in it.
  • components.ts- it simply defines the components in angular and this is the place where the app-root sector is also defined. A title attribute is also declared in the component.
  • component.html- it is the template file of the application which represents the visual parts of our components.

Q4.  Explain ngFor directive with an example.

The ngFor directive instantiates a template for every element of the given iterator. The different local variables of the ngFor directive can be used in iterations. The ngFor directive can even be used with the HTML elements. It also performs various changes in DOM. Several exported values can be aliased to local variables with the help of ngFor directive. It allows us to build data presentation lists and tables in our HTML templates. Here’s an example of ngFor directive with the help of HTML:

<tr *ngFor=”hero of heroes”>


Q5. Explain property binding or one way binding in angular js.

Basically, property binding means passing data from the component class and setting the value of a given element in the view. It is a one-way binding in which the data is passed from component to the class. It allows us to control the element property values from component to class. Property binding in angular can take place by three ways:

  • Interpolation can be used to define a value, as long as the value being defined is a string.
  • Wrapping brackets around the element property and binding it to the component property is the most common type of property binding.
  • The third way is by adding “bind” before the element property.

Q6. Explain ngIf directive with an example.

The ngIf is a built-in template directive which is used to add or remove some parts of DOM. This addition or removal depends on the expression being true or false.

If the expression is evaluated to false, then the ngIf directive removes the HTML element. If the expression is evaluated to be true, then the element gets added to the DOM.

Syntax- *ngIf=”<condition>” Example-
<ul *ngFor=”let person of people”

*ngIf=”person.age < 30”>


Q7. Write the difference between directive and component in angular js.

In angular js, there are differences between the meta-data annotations. Some of the differences are:

  • A directive is used to add behavior to an existing element. Whereas, a component is used to create a component with attached behavior.
  • "@directive" is used to create a directive. Whereas, "@component" is used to create a component.
  • A directive is used to attach different behaviors to an existing DOM element. Whereas, with the help of component, we can break our application into smaller components.
  • A directive is used to create reusable behavior. Whereas, a component is used to create reusable components.
  • A directive does not require a view. Whereas, a component needs a view via @view.

Q8. What do you understand by Isolated Unit Tests?

As the name implies, unit test is all about testing individual units of code. In order to answer some questions, isolating the unit of code under test is really important. When we do this, we are not forced into creating related pieces such as DOM elements for sorting. With the help of isolated unit tests, it becomes easier to implement everything. To simulate the requests, dependency injections are also provided. The individual sort function can be tested in isolation. And not only the sort function, any function can be tested in isolation.

Q9. What is a routing in angular js?

ngRoute module is used when you want to navigate through different pages of your application but you also want your application to be a single page application. This ngRoute module navigates through different pages of your application without reloading the entire application. The angular js route module should be included to make your application ready for routing. The ngRoute is added as a dependency in the application. The routing engine captures the specific url requested by the user and renders the view based on the defined routing rules.

Q10. What do you understand by services with reference to angular js?

Services in angular js are used to organize and share code across your application. These are the suitable objects which are wired together with the help of dependency injection. The angular js services are lazily instantiated. The service is only instantiated by angular js only when the application component depends on it. In angular js, new services can be made or can even be used in other built-in services. Over 30 built-in services are present in angular js.

  • 0
  • 1
  • 0
Angular2 interview questions

Angular2 interview questions..

Dear friends, below are the list of Angular2 interview questions that have been designed..

devquora devquora
Angular js interview questions

Angular js interview questions..

AngularJS interview questions and answers for beginners Read Angular js interview questions...

devquora devquora
IONIC framework interview questions and answers

IONIC framework interview ques..

Set of top Ionic Framework interview questions and answers. Below are list of Latest Ionic framework

devquora devquora