Angular Flashcards

1
Q

Name the building blocks of Angular.

A
  • Modules
  • Components
  • Templates
  • Directives
  • Data Binding
  • Services
  • Dependency Injection
  • Routing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s transpiling in Angular?

A

Transpiling is the process of converting the typescript into javascript. Though typescript is used to write code in the Angular applications, the code is internally transpiled into javascript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the Angular life cycle component execution happens when a data-bound input value updates?

A

ngOnChanges is the life cycle hook that gets executed whenever a change happens to the data that was bound to an input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s a lifecycle hook?

A

Directives and component instances have a lifecycle as Angular creates, updates, and destroys them. Developers can tap into key moments in that lifecycle by implementing one or more of the lifecycle hook interfaces in the Angular core library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Differentiate between components and directives in Angular.

A

Components break up the application into smaller parts; Directives add behavior to an existing DOM element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give examples of different lifecycle hooks in angular

A

ngOnChanges: respond when angular resets data-bound input properties

ngOnInit: Initialize the directive/component after Angular first displays the data bound properties and sets the directive/component’s input properties

ngDoCheck: Detect and act upon changes that Angular can’t or won’t detect on its own. Called during every change detection run, immediately after ngOnChanges() and ngOnInit()

ngAfterContentInit(): Respond after Angular projects external content into the component’s view / the view that a directive is in. Called once, after the first ngDoCHeck()

ngAfterContentChecked(): Respond after angular checks the content project into the directive/component.

ngAfterViewInit: Respond after angular initializes the component’s views and child views/ the view that a directive is in. Called once after ngAfterContentChecked

ngAfterViewChecked: Respond after angular checks the component’s views and child views / the view that a directive is in. Called after the ngAfterViewInit and every subsequent ngAfterContentChecked

ngOnDestroy: Cleanup just before angular destroys the directive/component. Unsubscribe observables and detach event handlers to avoid memory leaks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the use of @Input?

A

When it comes to the communication of Angular components, which are in Parent-child relationship; we use @Input in child components when we are passing data from parent to child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the use of @Output

A

@Output is used in child component to receive an event from to parent component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is ng-content directive?

A

The HTML elements like p or h1 have some content between the tags. For example, <p>this is a small paragraph</p> and <h1>this is a heading</h1>. Now, similar to this, what if we want to have some custom text or content between the angular tags like some related tax content This will not work the way it worked for HTML elements. Now, in such cases, the tag directive is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does a router.navigate do?

A

When we want to route to a component we use router.navigate. Syntax: this.router.navigate([‘/componentNmae’]);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is ViewEncapsulation?

A

ViewEncapsulation decides whether the styels defined in a component can affect the entire application or not. There are three ways to do this in Angular:

Emulated: Styles from other HTML spread to the component.

Native: Styles from other HTML do not spread to the component

None: styles defined in a component are visible to all components

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the services in angular and what command is used to create a service?

A

Services help us in not repeating the code. With the creation of services, we can use the same code for multiple components. To create a component, you use

ng g service NameOfService

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is dependency injection in Angular?

A

When a component is dependent on another component the dependency is injected/provided during runtime.

DI is a coding pattern in which a class asks for dependencies from external sources rather than creating them itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are dependencies?

A

Dependencies in angular are services or objects that a class needs to perform its function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is routing in angular?

A

Routing helps a user navigate to different components using links.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to handle events in Angular?

A

any activity (button click, mouse click, mouse hover) of a user on a frontend/web screen is termed as an event. Such events are passed from the view (.HTML) page to a typescript component (.ts).

17
Q

What is RouterOutlet?

A

RouterOutlet is a substitution for templates rendering the components. In other words, it represents or renders the components on a template at a particular location.

18
Q

Explain the usage of {{}}?

A

The set of brackets {{}} when used with an HTML tag, represent data from a component. For example, on a HTML page which has <h1>{{variableName}}</h1>, here the ‘variableName’ is actually typescript (component) data representing its value on the template, i.e. HTML. THis entire concept is called string interpolation.

19
Q

In how many ways the data binding can be done?

A

Data binding happens between HTML (template) and typescript (component). Data binding can be done in 3 ways:

1) property binding
2) event binding
3) two-way data binding

20
Q

What is the purpose of using package.json in the angular project?

A

With the existence of package.json, it will be easy to manage the dependencies of the project. If we are using typescript in the angular project, then we can mention the typescript package and version of typescript in package.json.

21
Q

How is SPA (single page application) technology different from the traditional web technology?

A

In traditional web technology, the client requests for a web page (HTML/JSP/asp) and the server sends the resource (or HTML page), and the client again requests for another page and the server responds with another resource. The problem here is a lot of time is consumed in the requesting/responding or due to a lot of reloading. Whereas, in the SPA technology, we maintain only one page (index.HTML) even though the URL keeps on changing.

22
Q

What is component in angular terminology?

A

A web page in angular has many components involved in it. A component is basically a bblock in which the data can be displayed on HTML using some logic written in typescript.

23
Q

What are ngModel and how do we represent it?

A

ngModel is a directive which can be applied on a text field. This is a two-way data binding. ngModel is represented by [()].

24
Q

What does a Subscribe method do?

A

it is a method which is subscribed to an observable. Whenever the subscribe method is called, an independent execution of the observable happens.

25
Q

Differentiate between observables and promises

A

Observables are lazy, which means nothing happens until a subscription is made. Whereas promises are eager; which means as soon as a promise is created, the execution takes place. Observable is a stream in which passing of zero or more events is possible and the callback is called for each event. promise handles a single event.

26
Q

What is an AsyncPipe in Angular?

A

When an observable or promise returns something, we use a temporary property to hold the content. Later, we bind the same content to the template. WIth the suage of AsyncPipe, the promise or observable can be directly used in a template and a temporary property is not required.

27
Q

Explain authentication

A

Authentication: the user login credentials are passed to an authenticate API (on the server). On the server side validation of the credentials happens and a JSON web token (JWT) is returned. JTW is a JSON object that has some information or attributes about the current user. Once JWT is given to the client, the client or user will be identified with taht JWT.

28
Q

Explain authorization

A

After a user logs in successfully, the authenticated or genuine user does not have access to everything. The user is not authorized to access someone else’s data, he/she is authorized to access some data.

29
Q

What is AOT compilation?

A

Every angular application gets compiled internally. THe angular compiler takes javascript code, compiles it and produces javascript code again. Ahead-of-Time compilation does not happen every time or for every user, as is the case with Just-in-time (JIT) compilation.

30
Q

What is redux?

A

it is a library which helps maintain the state of the application. Redux is not required in applications that are simple with the simple data flow, it is used in SPAs that have complex data flow.

31
Q

What are pipes?

A

This feature is used to change the output on the template; something like changing the string into uppercase and displaying it on the template. It can also change Date format accordingly.

32
Q

Differentiate between ngClass and ngStyle

A

in ngClass, the loading of CSS class is possible. in ngStyle, we can set the CSS style.

33
Q

Why TypeScript with angular?

A

Typescript is a superset of javascript. Earlier, javascript was the only client-side language supported by all browsers. The problem with javascript is, it’s not a pure object oriented programming language. Code written in JS without following patterns like prototype pattern becomes messy an dfinally leads to difficulties in maintainability and reusability. Instead of learning concepts (like patterns) to maintain code, programmers prefer to maintain code in an OOP approach and is made available with a programming language like TypeScript was thus developed by Microsoft in a way that it can wwork as javascript and offer what javascript cannot.

34
Q

Name the features of typescript

A

Pure OOPS as typescript offer concepts like generics, interfaces adn types which make it easier to catch incorrect data types passing to variables.

TS provides flexibility to programmers experienced in java, .net as it offers encapsulation through classes and interfaces.