Angular interview questions and answers-2020
1. What is Angular framework?
Angular is a TypeScript-based open-source front-end development platform that makes it easy to build the applications like web/mobile/desktop. The major features of this framework such as Single page application, Component, Directives, Dependency injection, end to end tooling, and many more other features are used to ease the development.
2. What is TypeScript?
TypeScript is a typed superset of JavaScript with extra features like classes, async/await, and many other features, and compiles to plain JavaScript. Angular built entirely in TypeScript and used as a primary language. You can install it globally as
   npm install -g typescript
Let's see a simple example of TypeScript usage,
function greeter(person: string) {
return "Hello, " + person; }
let user = "Sontosh";
document.body.innerHTML = greeter(user);
The greeter method allows only string type as an argument.3. What is the difference between AngularJS and Angular?
Angular is a completely revived component-based framework in which an application is a tree of individual components.
Some of the major difference in tabular form
                          Angular JS 
 |    
                                  Angular 
 |   
It is MVC   based architecture 
 |    
It is based on   Services/Controller 
 |   
It   uses  JavaScript to build the   application 
 |    
It uses Typescript to   build the application 
 |   
Based on   controllers concept 
 |    
It is  based  on the component UI approach 
 |   
It only   uses on Desktop Applications 
 |    
It  uses both mobile & desktop applications 
 |   
Difficulty   in SEO friendly application development 
 |    
Ease to create SEO   friendly applications 
 |   
4. What are the key components of Angular?
Angular has the below key components,- Component: These are the basic building blocks of angular application to control HTML views.
 - Modules: An angular module is a set of angular basic building blocks like component, directives, services, etc. An application is divided into logical pieces and each piece of code is called "module" which performs a single task.
 - Templates: This represents the views of an Angular application.
 - Services: It is used to create components that can be shared across the entire application.
 - Metadata: This can be used to add more data to an Angular class.
 
5. What are directives?
Directives add behavior to an existing DOM element or an existing component instance.
import { Directive, ElementRef, Input } from '@angular/core';
@Directive({ selector: '[myHighlight]' })
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}
Now this directive extends HTML element behavior with a yellow background as below
<p myHighlight>Highlight me!</p>
<p myHighlight>Highlight me!</p>
6. What are the components?
Components are the most basic UI building block of an Angular app which formed a tree of Angular components. These components are a subset of directives. Unlike directives, components always have a template and only one component can be instantiated per an element in a template. Let's see a simple example of an Angular component
import { Component } from '@angular/core';
@Component ({
selector: 'my-app',
template: ` <div>
<h1>{{title}}</h1>
<div>Learn Angular6 with examples</div>
</div> `,
})
export class AppComponent {
title: string = 'Welcome to Angular world';
}
7. What are the differences between Component and Directive?
In a short note, A component(@component) is a directive-with-a-template.
Some of the major differences are mentioned in a tabular form
 
 | 
  



0 Comments
Enter Your Comment...