w9 - angular 2 Flashcards

1
Q

Angular services?

A

A service is typically a class with a narrow, well-defined purpose. A Service is a broad category encompassing any value, function, or feature that an app needs

. Angular distinguishes components from services to increase modularity and reusability.

By separating a component’s view-related functionality from other kinds of processing, you can make your component classes lean and efficient

. A component can delegate certain tasks to services, such as fetching data from the server, validating user input, or logging directly to the console.

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

Dependency injection?

A

Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies. The Angular injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested. DI is wired into the Angular framework and used everywhere to provide new components with the services or other things they need.

Components consume services; that is, you can inject a service into a component, giving the component access to that service class. When Angular creates a new instance of a component class, it determines which services or other dependencies that component needs by looking at the constructor parameter types. For example, the constructor of ActorComponent needs HTTPService. When Angular discovers that a component depends on a service, it first checks if the injector has any existing instances of that service. If a requested service instance doesn’t yet exist, the injector makes one using the registered provider, and adds it to the injector before returning the service to Angular.

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

BrowserModule

A

exports required infrastructure for all Angular apps and

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

FormsModules

A

exports the required providers and directives for template-driven forms (i.e. it is required by the two-way binding directive ngModel), opens database.service.ts, and imports both HttpClient and HttpHeaders from angular http package:

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

http client

A

In the service’s constructor, add a reference to the httpClient:
constructor(private http: HttpClient) {}

By doing so, Angular will inject the httpClient into our service and make it available with reference http. Now, any method inside the service can make http requests by calling this.http (for instance this.http.get for a GET request).

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

Database service

A

Database Service

If you decide to serve the angular application by the backend application, then you must have relative addresses
getActors() {
return this.http.get(“/actors”);
}

if you decide to have a different machine (or different app) to serve the frontend pages, then you must provide a complete URL to the target endpoints as shown below:
const URL_BACKEND = “http://localhost:8080”;// or http://36.125.10.3:8081

deleteActor(id) {
let url = URL_BACKEND + “/actors/” + id;
return this.http.delete(url, httpOptions);
}

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

Observables?

A

To handle asynchronous operations,
Observables are declarative” that is, you define a function for publishing values, but it is not executed until a consumer subscribes to it.
The subscribed consumer then receives notifications until the function completes or until they unsubscribe. To execute the observable and begin receiving notifications, you call its subscribe() method, passing an observer (i.e. callback function).

all the http functions (get(),put(),post(), and delete()) return an observable output and our component has to call their subsucribe() methods to get them executed.

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

How does function ngOnInit() will get invoked?

A

Angular calls it shortly after creating the component

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

observables + e/g

A

It is a technique for handling asynchronous programming events and It allows a callback function to get executed once the data becomes available.”

xample->

onSaveActor(){

let obj = {name.this.fullName,bYear:this.bYear};

this.dbService.creatorActor(obj).subscribe(result => {

this.onGetActors();

));

}

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

getFleetSize() {
return this.http.get(‘/fleet/size’);
}

The component has a variable called fleetSize and it is declared as follows:

fleetSize: number;

A

getCurrentFleetSize(){

this.fleetSize.getFleetSize().subscribe((fleetS:Number)=>(

this.fleetSize=fleetS;

));

}

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

Selector?

A

A selector is used to identify each component uniquely into the component tree, and it also defines how the current component is represented in the HTML DOM

[]

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