Fudamentals Flashcards

1
Q

What and where is the Angular.json file?

A

A json file at the root level of the Angular workspace, provides project specific and workspace configuration details.

Such as path details for styles, scripts and assets.

And config for build and development tools by the CLI (e.g. serve.

A per-project config section and a few workspace properties

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

What is the purpose of the package.json file?

A

Configures the npm package (node) dependencies that are available for all projects in the workspace

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

What are NPM packages?

A

A package in Node.js contains the files you need for a module.

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

What is Node.js?

A

Node.js is an open-source server environment.

Allows you to run JavaScript on the server

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

What is the function of package-lock.json file?

A

Provides version information for all packages installed into node_modules by the npm client

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

What is the function of package-lock.json?

A

Provides version information for all packages installed in node_modules by the npm client

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

What is the function of the node_modules?

A

NPM packages are installed here and is accessible to the entire workspace.

The dependencies here will be visible to all projects (if its workspace wide)

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

In terms of programming, how does Node.js perform?

A

Node.js runs single-threaded, non-blocking, asynchronous programming

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

What is NPM?

A

NPM is a package manager for Node.js packages (and can be used for modules as well)

It is installed with Node.js

Consists of three main components:
-the website
-the CLI (command line interface)
-the registry

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

What is the public NPM registry?

A

A database of JavaScript packages.

It is used by developers to contribute & distribute their packages to communities (or local to their organisation) and also install others.

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

How do you use NPM?

A

Can be run via CLI with commands in a terminal.

‘npm …’

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

What is NVM?
And what is it used for?

A

Node Version Manager, a tool for (surprise) managing Node versions on your device.

Different projects on your device might be using different NPM versions, so can be provide version compatibility

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

What does the index.html file do?

A

The common name for the default page shown for a website (if no other page is specified)

Appropriately named as it serves an index to the main pages of the site

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

What is bootstrapping?

A

Bootstrapping is the process of initialising or loading the Angular application

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

What are the main steps in Bootstrapping?

A
  1. Load the Index.html file as the starting point for the app
  2. Loads Angular and third-party libraries/applications
  3. Executes the main.ts file as the application entry point (or as defined in the angular.json file for that project)
  4. Calls the bootstrapModule function to load and execute the Root module (app.module.ts)
  5. Executes the Root Component/s (example: app.component.ts) as defined in the Root Module in the bootstrap array. Sometimes called the Entry Components (not to be confused with the deprecated way to bootstrap)
  6. Display the Root Module Template (if called in the index.html)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the main.ts file do?

A

The file acts as the main entry point of the application, which is defined in the angular.json file.

It creates the browser environment with

‘Import {platformBrowserDynamic} from ‘@angular/platform-browser-dynamic’

And calls the bootStrapModule function to tell the builder to bootstrap the app:

‘platformBrowserDynamic().boostrapModule(AppModule)’

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

What does the App.module.ts file do when the application first loads?

A

This is the default name for the file that will bootstrap the initial components.

It loads the components listed in the bootstrap array under the ‘providers’ array. And it will insert each one into the DOM

Each of those bootstrapped components is the base of its own tree of components.

Most applications only have one component tree and bootstrap single root

18
Q

What is the root component?

A

The initial component bootstrapped by the app.module.ts when the application starts

And it is loaded into the DOM

19
Q

What are Angular Modules?

A

Angular NgModules are different to JavaScript (ES2015) modules

But like JS modules they can import functionality from other modules and allow their functionality to be exported.

NgModules is a class marked by the @NgModule decorator.

Ng Modules are basically containers for components.

As Angular loads items in a hierarchical tree structure, a list of components can be loaded in with the initialisation of that module

20
Q

Describe the structure of an Angular Module

A

A module will import the decorator class @NgModule from angular core and will have the decorator @NgModule ({…})

In which you have the following:

Declarations [ ]
Lists the component classes to be loaded in. As well as directives and pipes

Imports [ ]
Other modules to be loaded

Providers [ ]
Services are loaded in here and the bootstrap array

And then the export of the module along with any module specific functions.

21
Q

What is an Angular Component

A

Each Component defines a class that contains the application data and logic and is associated with an HTML template that defines a view.

Components will often load child components into its view via the selectors, forming a tree structure relationship

22
Q

Define the structure of a component

A

It will import the Component class from angular core and have the Component decorator @Component

The decorator defines the class as a component class and specifies its metadata.

In the decorator you have the following:

Selector:
The tag that other components (or in an html document) can use to reference this template. Which often build a view hierarchy

Template/TemplateUrl
Defines the component’s ‘host view’. This html is either put inline or as a relative path to a html file.

Providers
Like modules, can define an array of services that the component requires.

23
Q

What might you use to delimit a multi-line literal string for a template in the @Component?

A

A Template literal.

Delimits the string literal with backticks

template: <div>Hello World</div> <br>

24
Q

What is Data-Binding in Angular?

A

A mechanism for coordinating parts of a template with parts of a component.

Essentially allow you to send values, properties or events between the DOM and the Component.

Typically placed in the html of the template

Can be a two-way binding (send either direction) depending on the binding

25
Q

What are the types of Angular Data-Binding?

A

Component (source)
DOM (view)

{{value}}
Component —> DOM
Interpolation

[property] = “Value”
Component —> DOM
(sending a value to an element’s property in the DOM)
Property binding

(event) = “handler”
DOM —> Component
Event binding

[(ng-model)] = “property”
DOM <—> Component

26
Q

What is the ‘banana-in-a-box’ binding in Angular?

A

A two-way binding

When we use both the square and normal parentheses. But we can use either by its own

[(ng-model)] = “property”

The normal parenthesis would bind from DOM to Component

The square parenthesis would bind from Component to DOM

27
Q

What are Angular Pipes?

A

Allows you to declare display value transforms in your template HTML

Meaning you can perform a transforming function on your data in a interpolative binding, to modify or format that value.

{{interpolated_value | pipe_name }}

There are built-in pipes or you can make your own with the @Pipe decorator

28
Q

What is the Safe Navigation Operator? And what is it used for?

A

Used in bindings to prevent a compile error if the value is NULL.

Can add the operator in with a ? before the full stop

{{ event?.location?.name }}

(The above is accessing a Json object so multiple levels could be null)

29
Q

Are Components directives?

A

Technically yes, but because they are distinct enough in Angular they are defined with the decorator @Component.

The @Component extends the @Directive with template-oriented features

30
Q

What are Directives and how do they work?

A

A class that can modify the attributes in the DOM or its structure, as well as Component data.

They typically start with the ng prefix, i.e that *ngFor=“ “. This is a short-hand syntax that Angular interprets and converts to longer form (using <ng-template>)</ng-template>

A directive class definition must have the @Directive decorator (to supply the metadata)

It is usually associated with a HTML element or attribute.

When Angular finds a directive in an HTML template, it creates an instance of a matching directive class. It then gives it control over that portion of the browser DOM

31
Q

What is the syntax for referencing Directives?

A

*ngIf - Use lowerCamelCase when the directive applies to the html attribute

*NgIf - Use UpperCamelCase for when referring to the directive class, i.e, describing its behaviour & properties

32
Q

What are the types of Directives?

A

Attribute Directives - can modify behaviour and appearance of HTML elements, attributes, properties and Components.

Can be added in the template as a css attribute to that element.

Structural Attributes - can modify the structure of the DOM, such as adding, removing or manipulating elements. Such as *ngFor

Components - they use the @Component decorator which is an extension of the @Directive class

33
Q

Describe the structure of an Angular Directive

A

Will import the Directive class and have the @Directive decorator.

The Selector will be in square parentheses because its references as a HTML attribute and not an element (like Components)

Will also typically import the ElementRef class and have this in the structure to access the element its being applied to.

Constructor(ref:ElementRef) {
this.myEle = ref.nativeElement
}

34
Q

What the main ways components can communicate between each other and exchange data?

A

Using the @Input and @Output decorators

35
Q

What would you mainly use to send data from the Parent component to the child component?

A

The @Input decorator

The @Input is defined in the child component and then declared within the html selector used in the parent (calling) component

Child:

(Imports ‘Input’)
Selecttor: ‘child-app’

export class childComponent {
@Input( ) item = ‘ ’
}

Parent:

template:

<child-app [item]=‘myValue’ /child-app>

36
Q

What would you mainly use to send data from the Child component to the parent component?

A

The @Output decorator

The @Output is defined in the child component. It lets the parent component now that the property has change with an Event sent using the EventEmitter.

Which allows the user to create a custom event

Child:

(Imports ‘EventEmittet’ and ‘Output)

Selector: ‘childApp’

export class childComponent {
@Output( ) newEvent = new EventEmitter<string>( )</string>

doSomething(value:string) {
    this.newEvent.emit(value)
 }

Template: ‘

<input type=‘text’ id=‘inputbox’ #newItem>
<button type=‘button’ (click)=“doSomething(newItem.value)>Click me</button>’

}

Parent:

export class parentComponent {

parentMethod(item:string) {
//do something
}

template:

<child-app (newEvent)=‘parentMethod($event)’>< /child-app>

37
Q

What are Template Variables and what are they used for?

A

Used to reference data from one section of your template, in another section.

Often declared with the # symbol

Could refer to:
-a DOM element within a template
-a directive or component
-templateRef
-web components

Common example

<input #myVar placeholder=“enterValue” />

<button type=button (click=“doSomething(myVar.value)”>Click me</button>

Other example

The template var would be the temp variable defined in the ngFor

<div *ngFor=“let item of items”>
….
</div>

Where ‘item’ is the template var

38
Q

What is an ngClass used for? And explains its syntax

A

Used to assign CSS classes to the template html.

<html [ngClass]=“classx” /html>

Classes be assigned in an array, a single string or delimited (space) string or via an object when a value evaluates to truthy

[ngClass]=“{‘class1 class2’: true”}

39
Q

What is ngStyle and explain its structure

A

Applies styles to template html elements

<html [ngStyle]=“{‘font-style’: something} /html>

40
Q

What are the main Angular classes that use the Decorator class?

A

@Component
@Directive
@Pipe
@Injectable
@NgModule