Angular 2 Interview Questions and Answers Part 6

26. What is AOT compilation in Angular 2?

Answer:

AOT compilation stands for "Ahead of Time compilation". The AOT compiler converts the Angular HTML and TypeScript code into efficient JavaScript code during the build time instead of run time. The AOT complier provides a more robust application with higher security because of lesser client-side HTML and JavaScript code.

AOT compiler helps us to reduce the amount of synchronous request sent by the application.

Advantages of AOT Compilation:

  • It provides the Angular 2 application to download faster.
  • AOT compilation provides the faster rendering of the application.
  • Detect template errors earlier
  • Provides better security
  • Lesser Http request

27. What is @Input in Angular2?

Answer:

We use the @Input decorator to define an input for a component.

@Input decorator allows one way communication from parent to child. It binds a property within one component (child component) to receive a value from another component (parent component). To act as input property, the component property should be annotated with @Input decorator. A component can receive a value from another component using component property binding.

28. What is @Output in Angular 2?

Answer:

@Output decorator allows one way communication from child to parent component.

It binds a property of a component to send data from one component (child component) to calling component (parent component). @Output binds a property of the type of angular EventEmitter class. This property name becomes custom event name for calling component.

29. What is PrimeNG? How can it be used with angular2?

Answer:

PrimeNG is a collection of rich UI components for Angular 2. PrimeNG is a part of PrimeFaces library for Angular 2 application. PrimeFaces library is pretty popular for developing UI of JSF-based Web application. PrimeNG is developed by PrimeTek Informatics, a company with years of expertise in developing open source UI components. Using PrimeNG, an Angular 2 developer can use predefined components for development like tables etc. that saves time and effort.

30. What are the cookies in Angular 2?

Answer:

Cookies are small packages of information that are typically stored by our browser and websites.

We cannot store more than 20 cookies per web server and no more than 4KB information in each cookie.

In order to use the cookies in Angular 2, we have to install angular2-cookie library.

Following are the cookies method.
  • get()
  • getObject()
  • getAll()
  • put()
  • putObject()
  • remove()
  • removeAll()