Angular Flashcards

1
Q

What is angular

A

Angular is a powerful open-source framework developed by Google for building web applications. It follows a component-based architecture, where reusable components encapsulate HTML, CSS, and logic. Angular provides features like data binding, dependency injection, routing, directives, services, and TypeScript integration. It also offers a CLI for project scaffolding and automation. With Angular, you can build robust and scalable applications with ease.

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

How would you set up the angular environment?

A

Verify that Node.js and npm (Node Package Manager) are properly installed by running the following commands in your terminal:

node -v
npm -v
Install the Angular CLI globally by running the following command:

npm install -g @angular/cli
Create a New Angular Project:

ng new my-angular-app

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

Define a single page application

A

A Single Page Application (SPA) is a web application that operates within a single page, dynamically updating content without page reloads. It uses JavaScript and client-side frameworks like Angular or React to provide a seamless user experience, faster performance, and easier code maintenance. SPAs load initial resources upfront and fetch data asynchronously, resulting in a smooth and responsive application.

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

Define Ngmodule

A

NgModule is a foundational concept in Angular that organizes related components, directives, pipes, and services into cohesive units. It promotes modularity, reusability, and maintainability by grouping functionalities together. It defines the interactions between these elements and facilitates code organization and separation of concerns. By using NgModule, Angular applications can be structured, scalable, and efficient.

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

What is an angular component

A

An Angular component is a reusable and self-contained building block of an Angular application. It combines HTML templates, CSS styles, and TypeScript code to define a specific UI element or functionality. Components follow a component-based architecture, allowing for modular and scalable development. They have inputs and outputs for data exchange and can have lifecycle hooks for performing specific actions at certain points. Components promote code reusability, separation of concerns, and enhance the maintainability of Angular applications.

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

what is an angular Template

A

Template is a blueprint for a part of the user interface(UI).
Templates can be considered HTML documents, as they are written in HTML.
a special syntax can be used in templates to add additional functionality. this is an improvement over the normal HTML page.
As Angular template is only a part of UI, some tags like <html>,<body> are not included in templates.
Angular template is directly related to the component view.

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

What are template statements?

A

Template statements in Angular are used to handle user interactions and define the behavior of the application based on events. They are written directly in the HTML templates of Angular components using event binding syntax. By using template statements, you can create interactive and dynamic user interfaces, responding to user actions and updating the application state accordingly.

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

To define template reference variables.

A

Template reference variables in Angular allow you to capture references to specific HTML elements or Angular components within templates. They are defined using the “#” symbol followed by a name and are used to access and manipulate the referenced elements or components. Template reference variables are useful for accessing DOM elements or interacting with child components in parent components.

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

Describe one way binding

A

One-way binding in Angular enables a unidirectional flow of data from the component to the template. It allows you to display component data in the template without updating the component when changes occur in the template. One-way binding is denoted by square brackets “[]” and is useful for displaying data in the template based on the component’s state.

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

Describe two way binding

A

Two-way binding in Angular enables a bidirectional flow of data between the component and the template. It allows changes in the component to automatically update the template, and vice versa. Two-way binding is denoted by “[(ngModel)]” and is commonly used in form fields to keep the component and template data synchronized in real time.

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

Define Structural directives

A

Structural directives in Angular are special directives that allow you to dynamically manipulate the DOM structure based on conditions or collections. They include ngIf, ngFor, and ngSwitch. ngIf conditionally adds or removes elements, ngFor iterates over collections to generate elements, and ngSwitch displays different elements based on expressions. Structural directives provide flexibility in controlling element presence, repetition, and conditional rendering in Angular templates.

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

To define Angular Attribute directives.

A

Attribute directives in Angular allow you to modify the behavior and appearance of HTML elements by applying custom attributes. They are used to enhance elements with additional functionality or create reusable behaviors. Attribute directives can modify element behavior, manipulate properties, add event listeners, and change appearance by applying styles or animations. They are created using a TypeScript class with the @Directive decorator.

Examples
ngClass: used to add and remove a set of CSS classes.
ngStyle : used to add and remove a set of HTML styles.
ngModel: used to add two-way data binding to an HTML form element.

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

Most common examples of built-in structural directives

A

ngIf: used to conditionally create or dispose of subviews from the template.
ngFor: used to repeat a node for each item in a list.
ngSwitch: used for a set of directives that switch among the alternative views.

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

Pipes

A

In any full stack application, the data is received from the backend in HTTP format. when that data is displayed on the HTML page, the format should be changed. The pipes are used to transform data from one form to other.

Pipes are classified into two types.

Default Pipes
Custom Pipes
Data, currency, case and per cent are a few commonly used default pipes.

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

Custom pipes

A

Custom pipes in Angular are used to transform data in the template before rendering. They are created by implementing the PipeTransform interface in a TypeScript class. Custom pipes enable you to perform various transformations like formatting dates, sorting arrays, or applying custom logic. They are reusable and provide a convenient way to apply data transformations in Angular applications.

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

To define Dependency Injection Providers.

A

In Angular, the “provide” property is used to register a provider for dependency injection. It is part of the configuration for the Angular DI system and specifies how a dependency should be resolved and injected into a component, service, or other Angular construct.

To define a provider, you typically use the “provide” property along with the “useClass”, “useValue”, or “useFactory” properties. The “provide” property specifies the token or identifier that represents the dependency, while the other properties determine how the dependency is instantiated or resolved.

“useClass” is used to provide a class as the dependency, and Angular will create an instance of that class when injecting the dependency.
“useValue” is used to provide a specific value or object instance as the dependency.
“useFactory” is used to provide a factory function that returns the dependency instance.
By defining providers, Angular’s DI system knows how to resolve dependencies and inject them where needed throughout the application. This allows for loose coupling and easier maintenance of dependencies within an Angular project.

17
Q

Define Dependency injection

A

Dependency injection is A coding pattern in which a class receives the instances of the objects it needs (called dependencies) from an external source rather than creating them itself.
Dependency Injection helps to achieve code reusability and loose coupling

18
Q

To define Component Styles.

A

CSS styles are used to style the web pages.
Angular components are styled using CSS by styles, styleUrls, inline CSS in template and CSS imports.
styleUrls is most commonly used.

19
Q

To define View Encapsulation.

A

View Encapsulation is an important feature of Angular, to encapsulate components CSS into components view.
types of view encapsulation:

ViewEncapuslation.Emulated: default view, limits CSS styles scope to component level.
ViewEncapuslation.None: sets CSS styles scope to global.
ViewEncapuslation.ShadowDom: encloses css styles under shadow DOM. Global css styles are not applicable

20
Q

Angular Life Cycle (8)

A

Angular has a set of life cycle hooks that allow developers to tap into various stages of a component’s life cycle. These hooks can be used to perform various actions such as initializing and destroying component properties, detecting changes, and more.

Here are the main Angular life cycle hooks:

ngOnChanges - Called every time a component’s input properties change.
ngOnInit - Called once when the component is initialized.
ngDoCheck - Called during every change detection cycle.
ngAfterContentInit - Called once after the component’s content is initialized.
ngAfterContentChecked - Called after every check of the component’s content.
ngAfterViewInit - Called once after the component’s view has been initialized.
ngAfterViewChecked - Called after every check of the component’s view.
ngOnDestroy - Called just before the component is destroyed.
These hooks can be used to perform various actions such as initializing and destroying component properties, detecting changes, and more.

21
Q

To define Routing and Navigation.

A

In a single-page angular application, we change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page. As users perform application tasks, they need to move between the different views that you have defined.
To handle the navigation from one view to the next, you use the Angular Router. The Router enables navigation by interpreting a browser URL as an instruction to change the view.